Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Loop through 2 files in parallel

by rwitmer (Initiate)
on Nov 10, 2010 at 21:07 UTC ( [id://870696]=note: print w/replies, xml ) Need Help??


in reply to Re: Loop through 2 files in parallel
in thread Loop through 2 files in parallel

By george, I think this will work. You are truly a monktastic monk! Thanks!

Replies are listed 'Best First'.
Re^3: Loop through 2 files in parallel
by happy.barney (Friar) on Nov 11, 2010 at 07:50 UTC
    at least one error in previous code ... while condition is wrong.
    use strict; use warnings; my @FILES; open $FILES[0], '<', 'file1' or die; open $FILES[1], '<', 'file2' or die; my @w = map scalar <$_>, @FILES; my $empty = "blank line\n"; my %map = ( -1 => [ 0 ], 1 => [ 1 ], 0 => [ 0, 1 ], ); while (defined $w[0] && defined $w[1]) { my $cmp = $w[0] cmp $w[1]; print $cmp ? $empty : $w[0]; @w[ @{$map{$cmp}} ] = map scalar <$_>, @FILES[ @{$map{$cmp}} ]; } # Leftover lines in either file? print map $empty, map <$_>, @FILES;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://870696]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-24 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found