use CGI qw( :standard ); print( header() ); print( start_html() ); # A 2-D array is like an array of arrays. # Think of it as having rows that each contain an array of columns # First, create the array for the rows my @rowsArray; # Now we MUST explicitly create a column array for each row # We can't store the array directly, so will need to use a # reference to the column array for (my $ii=0 ; $ii < 3 ; $ii++) { # Create an empty column array my @aColArray; # Store reference to this column in the rows array $rowsArray[$ii] = \@aColArray; } # Now let's store some values in the array to demonstrate how to do so # Remember we need an extra $ to dereference to reference to the array my $col_ref; $col_ref = $rowsArray[0]; # get reference to array for row 0 $$col_ref[0] = "17"; # set column 0 of that array $$col_ref[1] = "23"; # set column 1 of that array $col_ref = $rowsArray[1]; # get reference to array for row 1 $$col_ref[0] = "fruit"; # set column 0 of that array $$col_ref[1] = "bar"; # set column 1 of that array $col_ref = $rowsArray[2]; # get reference to array for row 2 $$col_ref[0] = "cell (2,0)"; # set column 0 of that array $$col_ref[1] = "cell (2,1)"; # set column 1 of that array # Now let's print out the contents of the 2-D array for (my $ii=0 ; $ii < @rowsArray ; $ii++) { $col_ref = $rowsArray[$ii]; # Get reference to row $ii for (my $jj = 0 ; $jj < @$col_ref; $jj++) { print "cell ($ii, $jj) holds $$col_ref[$jj] \n"; } } print (end_html());