This is a "ragged" 2 D array (I guess, the "dots" aren't proper syntax)

AoA means that essentially X[0] is a reference to an array.

#!/usr/bin/perl use strict; use warnings; my @X = ([0,1],[0,0,0],[1,1,1,1,1,1,1,1,1]); #This is a ragged 2 D array foreach my $row_ref (@X) { print "num of elements this row: ", scalar (@$row_ref), "\n"; } __END__ num of elements this row: 2 num of elements this row: 3 num of elements this row: 9
Update: "ragged" means that each row has a different number of columns. That is completely fine. Often each row has exactly the same number of elements and that is called a "matrix", like 2 x 3 or 3x5, etc.

A simple array is like: @array=(1,2,3). A 2-D matrix is made up of references to arrays like that. So, essentially the first dimension of the 2D array is an array of references to other arrays that contain the actual data.

scalar @A returns the number of items in the first field. No...that would be the number of rows in the ragged 2D matrix.


In reply to Re: Find number of items in a field multi-demensional array by Marshall
in thread Find number of items in a field of a multi-demensional array by msnyder424

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.