Toss all that initialization stuff. It's not just unnecessary, it's wrong. Here's a demo to show you a full load/use cycle.
#!/usr/bin/perl -w use strict; # Build the table my $table_ref; for my $row (1..5) { for my $col (1..4) { my @results = rand_vals(4); $table_ref->[$row][$col] = \@results; } } # Use the table for my $row (1..5) { for my $col (1..4) { print "["; # Let Perl walk through the array for us #for (@{$table_ref->[$row][$col]}) { # print "$_ "; #} # Or index our way through the array explicitly for (0..$#{$table_ref->[$row][$col]}) { print "$table_ref->[$row][$col][$_] "; } print "] "; } print "\n"; } # Just a little tool for demo purposes sub rand_vals { my $elements = shift; my @ary; push @ary, int rand(9) for 1..$elements; return @ary; }
Prints out something like:
[2 4 4 1 ] [8 6 2 5 ] [8 3 1 5 ] [6 5 3 7 ] [4 6 1 0 ] [6 6 6 2 ] [6 4 7 5 ] [8 2 6 8 ] [6 7 0 8 ] [7 8 6 2 ] [5 1 6 6 ] [1 7 8 3 ] [1 8 2 7 ] [7 8 2 1 ] [6 3 8 7 ] [2 2 6 4 ] [7 8 7 4 ] [5 8 4 7 ] [4 2 6 0 ] [3 2 3 5 ]
You can, of course, use the uncommented inner loop for accessing results values, or delete that loop and uncomment the other one. Whichever suits your needs.

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall


In reply to Re: A Matrix of Arrays by dvergin
in thread A Matrix of Arrays by Anonymous Monk

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.