What about a HoH's, letting you store a count using the fruit as a key into a hash based on name, e.g.
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
I think this approach could work equally as well? Yielding, ...
$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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.