confused about nesting arrays
qxcozjn02_at_sneakemail.com
Date: 05/29/04
- Next message: Ricardo Signes: "Re: The >> operator"
- Previous message: Guruguhan \ N: "help in coding LHS"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 May 2004 01:33:32 -0700
Hello, I have run into a problem while writing a perl script. I am
fairly new to perl, and have done my best to search google and read
the perl documentation (as well as my o'reilly books) to try and solve
this problem I am having.
Basically, I need to nest an array within an array within a hash
element, then I need to use foreach and iterate through the first
array and then another foreach to iterate through the second array.
For some reason this isn't working for me. Here is a simplified
example of the code I am writing,
@fruits = ('apple', 'cherry', 'orange', 'peach');
@vegetables = ('carrot', 'asparagus', 'onion');
%world->{food}->[0] = (\@fruits, \@vegetables);
foreach $a (%world->{food}) {
foreach $b ($a) {
print $b[0];
}
}
I'm sure i'm doing something wrong, but i'm not sure how i'm supposed
to do this. Can anyone explain what is wrong with this code, and give
me an example of the correct way to go about this? That should point
me in the right direction hopefully heh.
Thanks,
Matthew.
- Next message: Ricardo Signes: "Re: The >> operator"
- Previous message: Guruguhan \ N: "help in coding LHS"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|