Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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....

Replies are listed 'Best First'.
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.

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://789194]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2017-12-11 02:42 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (286 votes). Check out past polls.