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

You will have undefined values in your @result array.

the above is plain wrong--

--shmem

Replies are listed 'Best First'.
Re^3: Using map and grep to Sort one list using another list
by johngg (Canon) on Feb 05, 2007 at 14:17 UTC
    I don't see that happening. Perhaps I have missed something.

    use strict; use warnings; use Data::Dumper; my @keys = qw{a e i o u}; my @records = qw{ 1|2|3|d|4 1|2|3|a|4 1|2|3|d|4 1|2|3|o|4}; my @result = map { my $key = $_; grep { m{^(?:\d\|){3}$key\|\d$} } @records } @keys; my $dd = Data::Dumper->new([\@result], [qw{*result}]); print $dd->Dumpxs();

    produces

    @result = ( '1|2|3|a|4', '1|2|3|o|4' );

    Cheers,

    JohnGG

Re^3: Using map and grep to Sort one list using another list
by Moron (Curate) on Feb 05, 2007 at 15:26 UTC
    My take on this was rather that when the grep fails to produce a match, it returns an empty list to map which then operates on no extra entries - i.e. doing nothing rather than constructing an undefined value.

    -M

    Free your mind