LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-10-2004, 10:40 AM   #1
inspleak
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:
mylist2
one
two
three

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, 03:22 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
Try this:
Code:
#!/usr/bin/perl

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


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

exit;
 
Old 03-10-2004, 03:24 PM   #3
inspleak
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...

thanks!
 
  


Reply


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 12:19 PM
how to find out an array size on c++ poeta_boy Programming 9 06-22-2004 02:28 PM
Size of an array in C Hady Programming 6 04-06-2004 06:33 AM
size of an array Longinus Programming 8 03-08-2004 02:48 PM
getting size of an array in c++ schatoor Programming 8 11-06-2003 06:19 PM


All times are GMT -5. The time now is 12:05 AM.

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