chuckawood has asked for the wisdom of the Perl Monks concerning the following question:
Hey all, I'm trying to cycle through a hash and manipulate the values. If I have this situation (not the prettiest coding but hopefully you follow what I'm doing):
my %Hash; $Hash{a}[0]="i"; $Hash{a}[1]="ii"; $Hash{a}[2]="iii"; $Hash{b}[0]="iv"; $Hash{b}[1]="v"; $Hash{b}[2]="vi"; foreach my $var (sort keys %Hash) { print "$var,$Hash{$var}[0],$Hash{$var}[1],$Hash{$var}[2],"; }
The output I get is: a,i,ii,iii,b,iv,v,vi,
So for each key ($var either a or b) I have three values assigned to elements 0, 1, and 2. Can I cycle through those elements with another foreach loop and manipulate them individually without explicitly calling it with $Hash{$var}[0]? Am I doing something stupid here or too complicated and there's something easier I could do? Is this even a clear enough picture for someone to answer? :P Thanks for whatever help you can provide.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple Hash values
by boftx (Deacon) on Mar 06, 2015 at 21:26 UTC | |
|
Re: Multiple Hash values
by marinersk (Priest) on Mar 06, 2015 at 21:26 UTC | |
|
Re: Multiple Hash values
by RichardK (Parson) on Mar 06, 2015 at 23:20 UTC | |
|
Re: Multiple Hash values
by CountZero (Bishop) on Mar 07, 2015 at 07:56 UTC | |
|
Re: Multiple Hash values
by karlgoethebier (Abbot) on Mar 07, 2015 at 16:06 UTC | |
|
Re: Multiple Hash values
by chuckawood (Initiate) on Mar 09, 2015 at 17:13 UTC |