in reply to variable number of lists

You might either need an array of arrays or a mixture of arrays and hashes. See perldata for hashes and perlreftut for how to put arrays into hashes and the other way round.

Replies are listed 'Best First'.
Re^2: variable number of lists
by AnomalousMonk (Archbishop) on Aug 17, 2009 at 15:33 UTC
Re^2: variable number of lists
by jbfamilly (Initiate) on Aug 17, 2009 at 15:22 UTC
    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....

      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.

      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.