Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-10-2004, 09:40 AM   #1
LQ Newbie
Registered: Jul 2003
Location: Michigan
Posts: 21

Rep: Reputation: 15
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!
Old 03-10-2004, 02:22 PM   #2
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Try this:

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

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

Old 03-10-2004, 02:24 PM   #3
LQ Newbie
Registered: Jul 2003
Location: Michigan
Posts: 21

Original Poster
Rep: Reputation: 15
Man.. thats great! thanks so much..

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

very cool...



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
c++: array size limit? bigfatdud Programming 14 01-27-2005 11:19 AM
how to find out an array size on c++ poeta_boy Programming 9 06-22-2004 01:28 PM
Size of an array in C Hady Programming 6 04-06-2004 05:33 AM
size of an array Longinus Programming 8 03-08-2004 01:48 PM
getting size of an array in c++ qanopus Programming 8 11-06-2003 05:19 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration