This is pretty basic stuff. Do you know how to do it in any language? If so perl does for loops and 2D arrays very similarly to many languages. Here is a little bit of code to get you started that uses a nice perl loop idiom (neater than the usual for($i=0; $i<21; $i++ ) { })
my @ary; my $c = 0; for my $row( 0..20 ) { for my $col ( 0..2 ) { $ary[$row][$col] = $c++; } } # have a look print "\t|0\t1\t2\n----+------------\n"; for my $row( 0..20 ) { print "$row\t|"; for my $col ( 0..2 ) { print "$ary[$row][$col]\t"; } print "\n"; } printf " The answer is %d --Deep Thought from Hitch Hikers Guide to the Galaxy\n", $ary[14][ +0];
Note that like most real languages Perl indexes its arrays starting from 0
cheers
tachyon
In reply to Re: Two dimentional array
by tachyon
in thread Two dimentional array
by algonquin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |