in reply to comparing arrays
We create a hash of good values from the masterfile, for quick lookup. Then we iterate over the lines in the data file, printing them only if the first value is a valid key.open(my $master_file, '<', "file1") or die "couldn't open master"; my %valid = map { chomp; ($_ => 1) } <$master_file>; close $master_file; open(my $data_file, '<', "file2") or die "couldn't open data file"; while (<$data_file>) { my ($key) = split /\s/; print if $valid{$key}; } close $data_file;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: comparing arrays
by Limbic~Region (Chancellor) on Sep 21, 2004 at 16:46 UTC |