On Mon, 22 Dec 2003, Charles K. Clarkson wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > : > : I have two text files I would like to open and read at the > : same time. Whats the best way to do this? > : > : I was think along these lines: > : > : open (TESTFILE, "<somefile.txt")|| die "can not open file"; > > It is helpful to add the perl error code in there: > > open (TESTFILE, "<somefile.txt") || > die qq|Cannot open "somefile.txt": $!"; > > : open (LOGFILE, "<my_other_file")|| die "can not open other file"; > > It would be helpful to know what you're going to do > with the files. Do they need to be synchronized? That is, > do you need to access the same line of each file together > or do you need to access lines of one file and different > lines of the other? > > Are they small files? Can they be safely loaded into > memory or are they going to be large files? Do you ever > need to go back to an old line you have already processed? > Will there ever be a need for more than three files? > Finally, are you using perl 5.6.1 or above? > > You're going to get some helpful answers, but more > information about what you intend to do with the files > can aid us in finding better solutions. > > > HTH, > > Charles K. Clarkson >
Thanks Charles, The files are smaller then 1000 lines, so dropping thme into a memory array would work. Dont see ever haveing to go back and re-read them, other then re-running the script. Would have to access the same line in each file at the same time. Runing Perl 5.8 on most systems, there are some systems that I'm not sure, but will assume that there running at least 5.6.1 Will need to ensure that each file has the same number of lines included. Was thinking of doing this via the "wc" command in unix. The thing that really stinks is not being able to load modules on the remote systems. I did hack some code out last night that looks like this: #!/usr/bin/perl -w my @test1; my @test2; my $x = 0; open (TEST1, "</etc/passwd")|| die " cant open passwd\n"; open (TEST2, "</etc/group")|| die " cant open group\n"; @test1 = <TEST1>; @test2 = <TEST2>; for ($x = 0; $x != $#test1; $x++) { print ($test1[$x]); print ($test2[$x]); print "\n"; } there's not any line count check.. figured I'd use something like this.. # make sure the files have the same number of lines @line_count = (`wc -l *tcp* *udp*`); ($lc, @rem) = split(" ",$line_count[0]); for (@line_count) { ($lc1_temp, @rem) = split (" "); } if ($lc1_temp/$#line_count != $lc) { die "\n\n\n Files do not have the same number of lines!\n\n\n"; } Thanks, Denis -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>