in reply to hash with identical keys
I think this approach could work equally as well? Yielding, ...use Data::Dumper; my %islanders; while (<DATA>) { chomp; my ($key, $cnt, $fruit) = split / /; $key =~ s/://g; $islanders{$key}{$fruit} += $cnt; } print Dumper(\%islanders); __DATA__ Gilligan: 1 coconut Skipper: 3 coconuts Gilligan: 1 banana Ginger: 2 papayas Professor: 3 coconuts MaryAnn: 2 papayas
$VAR1 = { 'Ginger' => { 'papayas' => '2' }, 'Gilligan' => { 'banana' => '1', 'coconut' => '1' }, 'Skipper' => { 'coconuts' => '3' }, 'MaryAnn' => { 'papayas' => '2' }, 'Professor' => { 'coconuts' => '3' } };
---
s;;:<).>|\;\;_>?\\^0<|=!]=,|{\$/.'>|<?.|/"&?=#!>%\$|#/\$%{};;y;,'} -/:-@[-`{-};,'}`-{/" -;;s;;$_;see;
Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash with identical keys
by props (Hermit) on Dec 07, 2007 at 21:33 UTC |