#!/usr/bin/perl use strict; # create some table rows my @a = qw(a b c); my @b = qw(c d e); my @c = qw(f g h); # create the 2D structure. my @table = (\@a, \@b, \@c); # @table is really a 1D structure, of references # but conceptually you can treat it as a 2D structure # (see the print_cube function) # this prints just the references print join(" ", @table), "\n\n"; # this function prints out the table print_cube(@table); # but since @table holds only references, you can change # the data being referenced and @table will in turn change # because they are really pointing the same thing @a = qw(x y z); print_cube(@table); # that is why multi dimensional structures are usually create # with anonymous structures: $table[0] = [1, 2, 3]; $table[1] = [4, 5, 6]; $table[2] = [7, 8, 9]; # that way to access the first row you have to go through # the table structure because the first row has not other # name than $table[0] (unlike @a above) print_cube(@table); sub print_cube { my @cube = @_; foreach my $i (0..2) { foreach my $j (0..2) { print $cube[$i][$j], " "; } print "\n"; } print "\n"; }