in reply to Loop through 2 files in parallel
Assuming file 1 is always a superset of file 2 the following does the trick:
#!/usr/bin/perl use strict; use warnings; my $str1 = <<STR; A B C D E F G STR my $str2 = <<STR; B D E G STR open my $in1, '<', \$str1; open my $in2, '<', \$str2; while (! eof $in1) { my $line2 = <$in2>; my $line1; print "blank line goes here!!\n" while defined ($line1 = <$in1>) && (! defined ($line2) || $line1 ne $line2); print $line2 if defined $line2; }
Prints:
blank line goes here!! B blank line goes here!! D E blank line goes here!! G
|
|---|