in reply to A Matrix of Arrays
Prints out something like:#!/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; }
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.[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 ]
------------------------------------------------------------
"Perl is a mess
and that's good because the
problem space is also a mess." - Larry Wall
|
|---|