in reply to Generating Hash-of-List using map?
probably not an expected answer:
DB<117> %hash=() DB<118> map { ($k,$e)=split '-'; push @{ $hash{$k} },$e } @CELLS => (1, 2, 3, 4, 1, 2, 1, 2) DB<119> \%hash => { A => [1, 2, 3, 4], B => [5, 6], C => [7, 8] }
update
or
DB<125> %hash=() DB<126> push @{ $hash{$_->[0]} } , $_->[1] for map {[split '-' ]} @ +CELLS => "" DB<127> \%hash => { A => [1, 2, 3, 4], B => [5, 6], C => [7, 8] }
or
DB<128> %hash=() DB<129> map { push @{ $hash{$_->[0]} } , $_->[1] } map {[split '-' +]} @CELLS => (1, 2, 3, 4, 1, 2, 1, 2) DB<130> \%hash => { A => [1, 2, 3, 4], B => [5, 6], C => [7, 8] }
or ( but not recommended b/c of possible side effects)
DB<135> %hash=() DB<136> map { @_=split '-'; push @{$hash{$_[0]}},$_[1] } @CELLS => (1, 2, 3, 4, 1, 2, 1, 2) DB<137> \%hash => { A => [1, 2, 3, 4], B => [5, 6], C => [7, 8] }
Cheers Rolf
( addicted to the Perl Programming Language)
In Section
Seekers of Perl Wisdom