To:
"'[EMAIL PROTECTED]'"
<[EMAIL PROTECTED]>, [EMAIL PROTECTED]
cc:
Subject:
RE: [Perl-unix-users] Nesting foreach
using multiple arrays
Hi Dan,
with your data model you could do that :
for my $PetIndex in ( 0 .. $#animals) {
prin
Hi Dan,
with your data model you could do that :
for my $PetIndex in ( 0 .. $#animals) {
print "animal = $animals[$PetIndex] and food = $petfood[PetIndex]\n";
}
But this is not so nice
What should be even better is to have a Hash in which you will store
everything about a pet
$PetTh
[EMAIL PROTECTED] wrote:
Hi, new to the list here; quick question !
How do I nest multiple arrays in one 'foreach' statement ?
ex.
@animals = ("cat",
"dog",
"ferret",
"mouse"
);
@petfood = ("meow mix",
"dog chow",
"ferret food",
"mouse food"
);
foreach $object (@animals) {
print "animal = $obj
Use a HASH instead of an array
[EMAIL PROTECTED] on 27 Jun 2003 14:27
Sent by:[EMAIL PROTECTED]
To:[EMAIL PROTECTED]
cc:
bcc:
Subject:[Perl-unix-users] Nesting foreach using multiple arrays
Hi, new to the list here; quick question !
How do I nest multiple arrays in one 'fore
definitely. What you want is a hash. It would look like
this:
###
my %animalandfood = (
'cat' => 'meow mix',
'dog' => 'dog chow',
'ferret' => 'ferret food',
'mouse' => 'cheese' ### changed this one on
ya!
);
foreach my $animal (keys %animalandfood)
{
print "an