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** 

_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to