in reply to variable number of lists

Here's one way to do it using a hash of arrays (HoAs). It is not necessarily the simplest or most efficient; but I think it illustrates one strategy that is in the vein of the various responses to your question. Similar strategies could work with Hash of Hashes (HOHs), Array of Arrays (AoAs).

#!/user/bin/perl use strict; use warnings; my %inventory = ('fruit'=>['apple','orange','banana'], 'veg' =>['celery','cucumber','bean'], ); my $num_days = scalar(@{$inventory{'fruit'}}); foreach my $day (1..$num_days){ my @menu = (); foreach my $food (keys %inventory){ push(@menu,"$food=>$inventory{$food}->[($day-1)]"); } print "Day $day: " . join(", ",@menu) . "\n"; } exit(0);

The code produces the output:

Day 1: fruit=>apple, veg=>celery Day 2: fruit=>orange, veg=>cucumber Day 3: fruit=>banana, veg=>bean

which I believe is the output that you're looking for.

The only proviso is that the number of entries for each type of food must equal the number of days to be populated. This could be handled alternatively (and without that restriction) by simply looking first for the type of food with the least number of entries and then restricting the number of days to be populated to that number of days. Or, of course, you could presumably work out a strategy that re-cycles through types of foods that have insufficient numbers of entries.

My offered solution does not handle those cases; but I don't think, IMHO, it is particularly hard to add that capability.

Note that I put the input data into a hash in the code. In your case you'd want to populate the hash from the input file that your user created. I presume you would know how to do that (if not, it's a good exercise for you).

Hope this helps and gives you some ideas in addition to all the great advice from the other Monks.

ack Albuquerque, NM