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

In reply to Re^5: Tk ::TableMatrix by zentara
in thread Tk ::TableMatrix by lil_v

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.