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;

Replies are listed 'Best First'.
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 ;)