in reply to Re^3: Tk ::TableMatrix
in thread Tk ::TableMatrix

thx alot... it helped me out a lot! Now, I'm faced with the challenge of putting all the datas into an array and print out the array.
for ($j=1, $j <= 10, $j++){ for ($i=1, $i <= 9, $i++){ @array = $arrayVar->{"$i,$j"}; } } print @array;
I only get one number when the output is printed, any ideas?

Replies are listed 'Best First'.
Re^5: Tk ::TableMatrix
by zentara (Cardinal) on Jul 02, 2008 at 19:53 UTC
    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"; }

    I'm not really a human, but I play one on earth CandyGram for Mongo