in reply to (Golf) List to Hash
FSR, '=>' was not being picked up by the qw function in the version of perl here (5.005); I switched to a split on a q function to test the case given:sub f { while(@_){while(($a=pop)ne'=>'){unshift@b,$a};unshift@{$h{pop()}},@b;@ +b=()}\%h }
my @h = split /\s+/, q[foo => zoo moo too bar => car far bar => zar tar qux => mux + ]; print Dumper f(@h); # output is: $VAR1 = { 'foo' => [ 'zoo', 'moo', 'too' ], 'bar' => [ 'car', 'far', 'zar', 'tar' ], 'qux' => [ 'mux' ] };
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
|
|---|