props has asked for the wisdom of the Perl Monks concerning the following question:
Gilligan: 1 coconut
Skipper: 3 coconuts
Gilligan: 1 banana
Ginger: 2 papayas
Professor: 3 coconuts
MaryAnn: 2 papayas
I have to create for each name a respective file such as this gilligan.info with its fruit written in the file . Like gilligan.info must have written in it : Gilligan: 1 coconut Gilligan: 1 banana.#my code: #this fails since two Gilligan keys exist use warnings; use strict; open( DATA, 'data' ) or die "i cannot read data:$!\n"; my %hash; while (<DATA>) { my ( $name, $item ) = split(/:/); $hash{$name} = $item; for my $name ( keys %hash ) { my $lc_name = lc $name; open( FILE, ">$lc_name.info" ) or die "cannot open FILE:$!\n"; print FILE "$name $hash{$name}"; } }
The trouble is that i shouldn't be using hash because there are 2 identical key entries(Gilligan). Now I've experimented with HoA with no luck some guidance is more than welcome
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash with identical keys
by tuxz0r (Pilgrim) on Dec 06, 2007 at 22:20 UTC | |
by props (Hermit) on Dec 07, 2007 at 21:33 UTC | |
|
Re: hash with identical keys
by moritz (Cardinal) on Dec 06, 2007 at 22:09 UTC | |
|
Re: hash with identical keys
by brian_d_foy (Abbot) on Dec 07, 2007 at 02:14 UTC | |
|
Re: hash with identical keys
by aquarium (Curate) on Dec 06, 2007 at 22:30 UTC |