[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 = $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 ?
The others are trying to tell you to use a hash. You can just
as easily do it with the parallel arrays (and probably faster):
for (my $ii = 0; $ii < @animals; $ii++) {
print "animal = $animals[$ii] and food = $petfood[$ii]\n";
}
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs