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)
|