Kevin Old wrote:
> 
> Hello all,
> 
> I know this has been asked a few times over the years, but I can't find
> an answer that is what I need in the archives.
> 
> I have 2 files. I have a for loop.  I need to read from both files with
> 1 file handle, or whatever will allow my code to read from both files
> alternating between them.
> 
> Basically I need the equivalent of this:
> 
> #open file1
> #open file2
> 
> while (<file1> || <file2>) {
> 
> #process line from file1
> #process line from file2
> 
> }
> 
> I've tried the Perl Cookbook recipe for reading from multiple
> filehandles and I need more than just to have a list of file handles
> returned.  I need to be able to read (and process) a line from each file
> handle so that they finish at about the same time.  Not a solution that
> reads one file then the other.
> 
> Any help is appreciated.


Something like this should work.

open F1, 'file1' or die "Cannot open 'file1': $!";
open F2, 'file2' or die "Cannot open 'file2': $!";

while ( my $line1 = <F1> and my $line2 = <F2> ) {

    #process line from file1
    #process line from file2

    }



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to