-   Programming (
-   -   PERL: Size of an array of an Array (

inspleak 03-10-2004 09:40 AM

PERL: Size of an array of an Array
Hey guys... here is the situation:
@list1 = ("one", "two", "three");
@list2 = ("myList2");
@fooList = ([@list2], [@list1]);

Basically what I want to do is walk down each array in
@fooList. For instance I want to read data from @list2,
element at a time, then @list1, but I want to be able to
add new arrays to @fooList at any time. So I don't know
the size of @fooList or any of the arrays ahead of time.

So I want it to work like this (though it doesn't :))

foreach $thing1 (@fooList)
foreach $currentThing ($fooList[$thing1]);
print "$currentThing\n";

So what I would like to happen in this case is have it print out each
element in each list.

so output would be like:

I could use "for" loops but I would need to know the sizes of the arrays inside @foolist on the fly, and I couldn't figure out how to do that either..

Or I might just be crazy..

Thanks much for the help!

david_ross 03-10-2004 02:22 PM

Try this:


@list1 = ("one", "two", "three");
@list2 = ("myList2");
@fooList = ([@list2], [@list1]);

foreach $thing (@fooList){
 foreach $currentThing (@{$thing}){
  print "$currentThing\n";


inspleak 03-10-2004 02:24 PM

Man.. thats great! thanks so much..

I didn't realize you could reference like that..

very cool...


All times are GMT -5. The time now is 09:10 PM.