Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by shmem (Canon)
on Feb 05, 2007 at 13:16 UTC ( #598285=note: print w/ replies, xml ) Need Help??


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

Sure you can use map:

my @final = grep {@$_} map { my $key = $_; [ grep{ m/^\d\|\d\|\d\|$key\|\d$/ } @records ] } @keys;

But I am missing the 'sort' bit of the title in your code...

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}


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:37 UTC
    The sort is a mistake. Just keeping you on your toes. Now, no one's gonna believe this but ......... I'm sure while trying to solve this problem I wrote the following code
    my @keys = ( qw|a e i o u| ); my @records = (); push @records, '1|2|3|d|4'; push @records, '1|2|3|a|4'; push @records, '1|2|3|d|4'; push @records, '1|2|3|o|4'; my @final = (); my @result = (); @result = map { my $index = $_; grep{ m/^\d\|\d\|\d\|$keys[$index]\|\d$/ } @records } 0..$#keys; print map{ "$result[$_]\n" } 0..$#result
    which didn;t work. And while replying to your soln, I just re-ran that code and it worked!!!!!!! Hmmmmmmmmmm. Thank you all for replying anyway. I feel such a fool. -Ants

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2015-07-04 22:33 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 (60 votes), past polls