Program to demonstrate a pointer to a two-dimensional array : Multidimensional Arrays « Array « Perl






Program to demonstrate a pointer to a two-dimensional array

    


#!/bin/perl

my $matrix = [
               [ 0, 2, 4 ],
               [ 4, 1, 2 ],
               [ 2, 5, 7 ]
             ] ;

print "$matrix->[2]->[1].\n";

for($x=0;$x<3;$x++){
     for($y=0;$y<3;$y++){
        print "$matrix->[$x]->[$y] ";
     }
     print "\n\n";
}
for($i = 0; $i < 3; $i++){
     print "@{$matrix->[$i]}", "\n\n";
}
$p=\$matrix;     # Reference to a reference
print ${$p}->[1][2], "\n";

   
    
    
    
  








Related examples in the same category

1.Multidimensional Arrays(Lists of Lists)
2.Using multi-dimensional array references.
3.Using multi-dimensional array references again.
4.Lists of Lists
5.How to use two dimensional arrays
6.Output two -dimensional array
7.References to Simulate Multi-Dimensional Arrays
8.Using array reference to create two-dimensional array
9.Using @ operator and one dimensioanal array to create two dimensioanl array
10.Two dimensional array is array of array
11.A three-dimensional array
12.Using array reference to index the two dimensional array
13.Using two-dimensional array
14.'use strict' with two dimensional array
15.Array of array
16.Reference the outter array of an two dimensional array
17.Two dimensional array is array scalar plus array
18.Using the -> to reference the elements of a two-dimensional array