Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Using map and grep to Sort one list using another list

by davorg (Chancellor)
on Feb 05, 2007 at 13:28 UTC ( #598289=note: print w/ replies, xml ) Need Help??


in reply to Using map and grep to Sort one list using another list

I think the (ahem!) key here is to convert your @keys array into a hash to make it easier to check for the existance of keys in your data line.

my @keys = ( qw|a e i o u| ); my %keys = map { $_ => 1 } @keys; my @records = ( '1|2|3|d|4', '1|2|3|a|4', '1|2|3|d|4', '1|2|3|o|4', ); my @final; my @result; foreach (@records) { if ($keys{ (split /\|/)[3] }) { push @result, $_; } } print map { "$_\n" } @result;


Comment on Re: Using map and grep to Sort one list using another list
Download Code
Re^2: Using map and grep to Sort one list using another list
by AntsPants (Novice) on Feb 05, 2007 at 13:41 UTC
    I agree but this morning I spoke to the person who has this problem and they said they wanted to keep the code as lists!!! Will have another friendly chat with them ;)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-12-28 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls