Below is some code. You don't even have to use foreach if you know that you want the 6th..10th things as shown below.

There are some folks who like to call @thingie an array, and folks who like to call @thingie a list. I figure there are some valid arguments on both sides, but that is not the point below..

#!/usr/bin/perl -w use strict; my @mainarr; my @arr1=qw(a b c d e); my @arr2=qw(f g h i j); my @arr3=qw(k l m n o); push(@mainarr,@arr1); push(@mainarr,@arr2); push(@mainarr,@arr3); # you have flattened each list into a single list # The "push" is similar to a queue operation # that adds things to the end of the queue. # there are 4 Perl ops that you should read more # about (push,pop,shift,unshift), all of these operate # on lists. print "@mainarr\n"; # that prints: a b c d e f g h i j k l m n o print join(" ",@mainarr[5..9]),"\n"; # this is a list slice and prints the 6th-10th things... # this prints: f g h i j #If you want to maintain the integrity of these things #that you "push" onto @mainarr, then they have to be #grouped together. The way to do that is with a #reference to a list. This creates a LoL, a List of List. push(@mainarr,[@arr1]); push(@mainarr,[@arr2]); push(@mainarr,[@arr3]); print "@mainarr\n"; #will produce something like: #ARRAY(0x182a64c) ARRAY(0x183642c) ARRAY(0x183649c) foreach $list_ref (@mainarr) { print "@$list_ref\n"; } #this prints: #a b c d e #f g h i j #k l m n o

In reply to Re: Array of array by Marshall
in thread Array of array 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.