in reply to Re^5: Help understand why this grep does not work
in thread Help understand why this grep does not work

OK, these two three possibilities seem to do it, but by far not as performant as the or-ed regex.

DB<126> %hash = map { my ($m)=/^(\w\s+\d)/; $m => [ grep {/^$m/} @da +ta2 ] } @data1 => ("a 1", [], "a 2", ["a 2 Y"], "a 3", ["a 3 R"]) DB<127> %hash = map { my $k=$_ ; $k => [ grep {/^$k/} @data2 ] } map + { /^(\w\s+\d)/} @data1 => ("a 1", [], "a 2", ["a 2 Y"], "a 3", ["a 3 R"]) DB<128> %hash = map { /^(\w\s+\d)/; $1 => [ grep {/^$1/} @data2 ] } +@data1 => ("a 1", [], "a 2", ["a 2 Y"], "a 3", ["a 3 R"])

update

see also Generating Hash-of-List using map?

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^7: Help understand why this grep does not work
by drmrgd (Beadle) on Nov 02, 2013 at 17:10 UTC
    Very informative; thank you! This definitely starts to drift into the 'difficult to read and maintain' territory, though. You've been a big help giving me some insight on how to play around with 'map' a little more, though. Thanks again!