in reply to comparing arrays
The advantage of this code is it's simple and easy to edit for other formats by changing the regular expression (currently set for one or more digits followed by a space) and comparisons (change to lt, eq, gt for string keys). It also doesn't require huge arrays or hashes.open(INPA, $inpa) || die "Can't open $inpa"; open(INPB, $inpb) || die "Can't open $inpb"; my $a = <INPA>; chomp($a); my $b = <INPB>; while ($a && $b) { $b =~ /^(\d+) /; if ($a < $1) { $a = <INPA>; chomp($a); } elsif ($a == $1) { print $b; $a = <INPA>; chomp($a); $b = <INPB>; } else { $b = <INPB>; } } close(INPA); close(INPB);
|
|---|