In Perl, a 2-D array is an array of references to 1-D arrays.
Look at Data Type: Array in the Tutorials section of Perl Monks.
A Perl 2-D array can have a different number of "columns" on each "row".
#!/usr/bin/perl use strict; use warnings; my @ar1 = (["one", "two"], ["three", "four", "five"]); my $count = scalar @{ $ar1[1] }; print "count: Elements in 2nd Row = $count\n"; print "number of dimensions =", scalar @ar1, "\n"; my $total_elements; foreach my $row_ref (@ar1) { $total_elements += @$row_ref; } print "total elements in array:ar1=$total_elements\n"; __END__ count: Elements in 2nd Row = 3 number of dimensions =2 total elements in array:ar1=5

In reply to Re: Count elements in multidimensional arrays by Marshall
in thread Count elements in multidimensional arrays by klorentzen

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.