1t Note: $#array is not the length, but the biggest index.

2nd note:use strict

#!/usr/bin/env perl use strict; my $ar1 = [1,2,3]; my $ar2 = [4,5,6,7]; my @arrays = ($ar1,$ar2); foreach my $ary (@arrays) { print $#{ary}, "\n"; } __END__ Global symbol "@ary" requires explicit package name at test.pl line 10 +. Execution of test.pl aborted due to compilation errors.

3d note: Read perldata and perlref! Really, that helps a lot!

4th note:

#!/usr/bin/env perl use strict; use warnings; my $ar1 = [1,2,3]; my $ar2 = [4,5,6,7]; my @arrays = ($ar1,$ar2); foreach my $ary (@arrays) { # correct syntax print $#{@$ary}, "\n"; # correct length print scalar(@$ary), "\n"; }

regards,
tomte


Hlade's Law:

If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.


In reply to Re: pushing into arrays of arrays by Tomte
in thread pushing into arrays of arrays by Anonymous Monk

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.