in reply to Array of array

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