Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: comparing arrays

by rjbs (Pilgrim)
on Sep 21, 2004 at 15:31 UTC ( #392681=note: print w/ replies, xml ) Need Help??


in reply to comparing arrays

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;
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.
rjbs


Comment on Re: comparing arrays
Download Code
Re^2: comparing arrays
by Limbic~Region (Chancellor) on Sep 21, 2004 at 16:46 UTC
    rjbs,
    Though the AM didn't state it as a requirement, I wanted to point out that your solution does not preserve order.

    Cheers - L~R

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-08-28 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls