If this works:
print $people[0][0]->name;
then looping would work like this:
foreach ( @{$people[0]} ) { print $_->name; }
Or you could do it like this:
foreach $row ( @people ) { foreach $cell ( @$row ) { print $cell->name; } }
The point is that each element in @people is itself an array reference, and needs to be treated as such. In the first example, in order to dereference an element of @people as an array, you need the curly braces between the "@" and the expression that represents the array ref.

In the second example, doing the dereferencing in two stages makes the syntax less messy. At each iteration of the outer loop, $row is set to the array ref for the inner dimension of @people, and is easier to dereference.


In reply to Re: Looping through an array of objects by graff
in thread Looping through an array of objects by dalziel

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.