Thank You all for your help.  I had the data store in 2 seperate arrays to begin with and I went with
for (my $ii = 0; $ii < @animals; $ii++)


        {
print balh blah blah

}
Thank you,
**DAN**



EUROSPACE SZARINDAR <[EMAIL PROTECTED]>

06/27/2003 12:30 PM

       
        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) {
   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

$PetThings = { cat => {food => "meow mix",
                                color =>"black"},
                      dog =>{food =>"dog chow"},
                       fish =>{food => "fish food"}                  
}

foreach my $pet (%$PetThings ) {
   print "$pet eats $PetThings ->{$pet}{food] \n";
   }



Something like that.
take a look at the "perldoc perldsc" it is a very usefull manual.

Michel


-----Message d'origine-----
De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Date: vendredi 27 juin 2003 15:28
À: [EMAIL PROTECTED]
Objet: [Perl-unix-users] Nesting foreach using multiple arrays



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 = $object and food = @petfood";
 }

The results I am lookg for are

animal = cat and food = meow mix
animal = dog and food = dog chow
animal = ferret and food = ferret food
animal = mouse and food = mouse food

Thanks alot for you help

Is there a better way of doing this also ?

**DAN**


Reply via email to