You're not going blind nor insane but your mission is half-way through, cheers, your multi-dimensional array has been assigned and built successfully, for each element in the dimension referenced you need to appropriately dereference it to be able to access it...

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:

for (my $i=0;$i<=$#ary; $i++){ print "==>$ary[$i][0]\n"; # print "==>@{$ary[$i]}[0]\n"; # print "==>$ary[$i]->[0]\n"; }

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...


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

In reply to Re: Multi dimentions to a single dimentional array by biohisham
in thread Multi dimentions to a single dimentional array by Massyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.