Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 having an uproarious good time at the Monastery: (5)
As of 2015-07-02 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls