LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 09: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, 02:22 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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, 02: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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:39 PM.

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
Open Source Consulting | Domain Registration