Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: variable number of lists

by jbfamilly (Initiate)
on Aug 17, 2009 at 15:22 UTC ( #789194=note: print w/ replies, xml ) Need Help??


in reply to Re: variable number of lists
in thread variable number of lists

Missed an important point. I need to know which list the data is coming from. More accurate result would be:

Day 1: fruit=apple veg=celery Day 2: fruit....


Comment on Re^2: variable number of lists
Download Code
Re^3: variable number of lists
by moritz (Cardinal) on Aug 17, 2009 at 15:24 UTC
    For example by iterating over the indexes of one array, and accessing the the items "simultaneously" (whatever that means if you don't use threads...) by index.
Re^3: variable number of lists
by ssandv (Hermit) on Aug 17, 2009 at 15:31 UTC

    Basically, you either know all the lists are the same length, or you extract the length of the longest one programmatically (you say you know how to make the data structure so I assume you know how to access it). Once you have that information, do a foreach $element_num (1..$foo) { where $foo is your number of elements in the longest list. For each number, you extract one element from each list with an internal foreach loop that uses keys to get you the individual list names.

    Alternately, you could make an array of arrays and just make element 0 of each row the name of that list--then it should be fairly obvious how to march across all the rows in lock-step. It depends on whether you want easy access to the data by list name.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://789194]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (18)
As of 2014-08-01 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (27 votes), past polls