First you are not seeing the problem. As a lesson on your code,
you have your logic all screwed up. Since you don't reset $i after each inner loop run, you don't cycle thru everything. Furthermore, you assign @array to the same undefined reference each time.... so you get one entry.YOUR REAL PROBLEM is you don't understand the data structure involved, it's already there in the hash, all you need to do is pull it out. Read "perldoc perlreftut" and see References quick reference. The following code should show you what's up. Don't let the name $arrayVar throw you off, it's actually an hashref for %$arrayVar.
#!/usr/bin/perl
my $arrayVar = {}; # this is actually a hashref
print "Filling Array...\n";
my ($rows,$cols) = (10, 10);
foreach my $row (0..($rows-1)){
foreach my $col (0..($cols-1)){
$arrayVar->{"$row,$col"} = 2*$row + 3*$col;
}
}
foreach my $key (sort keys %$arrayVar){
print "$key -> ",$$arrayVar{$key},"\n";
#or
# print "$key -> ",$arrayVar->{$key},"\n";
}
|