in reply to Multi dimentions to a single dimentional array
When you loop through the first dimension you'd be looping through anonymous arrays as elements of that dimension hence $f would refer to an anonymous array, dereferencing that anonymous array using the infix arrow operator would enable you access its elements in turn too..
use strict; use warnings; my @ary = ( #First Dimension ['Jan', 10, 20], #second Dimension ['Feb', 15, 25], ['Mar', 30, 33] ); foreach my $f (@ary) { print "==> $f->[0]\n"; #infix Arrow Operator dereferencing.. #print "==> @{$f}[0]\n"; #another way of dereferencing too..(T +ry It) }
Update: You can still achieve the same through indexing in a for loop, here are some of the different ways this is possible:
It's worthwhile investing time in reading Perl data structure cookbook, manipulating arrays of arrays in Perl, References Tutorial and the Monastery's very own tutorials on the subject at References...for (my $i=0;$i<=$#ary; $i++){ print "==>$ary[$i][0]\n"; # print "==>@{$ary[$i]}[0]\n"; # print "==>$ary[$i]->[0]\n"; }
|
|---|