Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

3 way hash maps

Status
Not open for further replies.

stort

Programmer
Feb 17, 2006
10
0
0
GB
hi guys,

is it possible to have a hash map that has one key with two separate values, ie:

key#1 value#1 value#1
key#2 value#2 value#2
key#3 value#3 value#3
key#4 value#4 value#4
etc.....

i currently have a hash map with one key and one value but wanted to know if the above is possible

also how do i access the contents of a value. for example, if value#1, value#2, value#3 and value#4 all contained integers, how would i total them?

thanks
 
You'll probably want to use a hash of arrays to accomplish this. See if this helps:
Code:
my %HoA;

$HoA{'one'} = [1,2];
$HoA{'three'} = [3,6];
$HoA{'five'} = [5,10];
$HoA{'ten'} = [10,20];

my $sum;
foreach my $key (keys %HoA) {
    print "$key:\n";

    foreach (@{$HoA{$key}}) {
        print "\t$_\n";
        $sum += $_;
    }
}
print "\nSum: $sum\n";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top