Mega Code Archive

 
Categories / Perl / Array
 

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";