S
Sal
#!/usr/bin/perl
use strict;
use warnings;
my %sum = {};
for (my $i = 1; $i <= 6; $i++) {
for (my $j = 1; $j <= 6; $j++) {
for (my $k = 1; $k <= 6; $k++) {
my $tot = $i+$j+$k;
my $key = "$i " . "$j " . "$k ";
$sum{$key} = $tot;
print "$i " . "$j " . "$k " . " $tot\n";
}
}
}
foreach my $key (sort keys %sum) {
print "$key => $sum{$key}\n";
}
When the above is executed it first prints the entire hash, then
returns the error:
Use of uninitialized value $sum{"HASH(0x95fe818)"} in concatenation
(.) or string at ./3dice.pl line 19.
HASH(0x95fe818) =>
Why is the last hash value blank?
use strict;
use warnings;
my %sum = {};
for (my $i = 1; $i <= 6; $i++) {
for (my $j = 1; $j <= 6; $j++) {
for (my $k = 1; $k <= 6; $k++) {
my $tot = $i+$j+$k;
my $key = "$i " . "$j " . "$k ";
$sum{$key} = $tot;
print "$i " . "$j " . "$k " . " $tot\n";
}
}
}
foreach my $key (sort keys %sum) {
print "$key => $sum{$key}\n";
}
When the above is executed it first prints the entire hash, then
returns the error:
Use of uninitialized value $sum{"HASH(0x95fe818)"} in concatenation
(.) or string at ./3dice.pl line 19.
HASH(0x95fe818) =>
Why is the last hash value blank?