in reply to Generating Hash-of-List using map?
All proposals are cheating so far! Here is what you are looking for (warning: dirty code!)
my %hash = map { /^([^-]*)-(.*)$/; if( $1 eq ($a//'-') ) { push @$b, $ +2; () } else { ( $a = $1 => $b = [ $2 ] ) } } @CELLS;
Of course, should $a accidentally be identical to the bit left of the hyphen in the first element of @CELLS, then it fails...
UPDATE: Small improvement on the else branch.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Generating Hash-of-List using map?
by LanX (Saint) on Sep 23, 2013 at 21:12 UTC | |
by hdb (Monsignor) on Sep 24, 2013 at 06:17 UTC | |
by LanX (Saint) on Sep 24, 2013 at 10:19 UTC |