And now a more concise form:use strict; use warnings; my $file1 = make_func (shift); my $file2 = make_func (shift); while (1) { my $line1 = $file1->(); my $line2 = $file2->(); last unless defined $line1 and defined $line2; print "$line1 $line2 \n"; } sub make_func { my $file = shift; open my $FH, "<", $file or die "could not open $file $!"; return sub {my $c = <$FH>; return unless defined $c; chomp $c; return $c } }
It can probably be made more concise, but I have no time right now.use strict; use warnings; my $file1 = make_func (shift); my $file2 = make_func (shift); my ($line1, $line2); chomp $line1 and print $line1, $line2 while ($line1 = $file1->() and $ +line2 = $file2->()); sub make_func { my $file = shift; open my $FH, "<", $file or die "could not open $file $!"; sub {<$FH>; } }
In reply to Re: Use 2 files and print each line of each one side-by-side
by Laurent_R
in thread Use 2 files and print each line of each one side-by-side
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |