-----Original Message----- From: Stefan Weckx [mailto:[EMAIL PROTECTED] Sent: Friday, June 18, 2004 1:38 AM To: [EMAIL PROTECTED] Subject: array
>hi list, >2 questions about arrays: >- I want to take 2 elements a time from an array within a foreach >control structure, which should be something like: >foreach $a $b (@array) {...}. it this possible in perl?? Here's one way: while(@array){ my $a = shift @array; my $b = shift @array; } ...I think that would do what you're asking. >- is it possible to search an array for a certain element, and that the >search returns the element index? eg. searching for 156 in the array >(123, 456, 156, 1354, 35164, 654656, 654, 846) should give 2 This one's easy. for(0..$#array){ chomp $_; if($_ == 156){ print "Found 156 at $_.\n"; last; } } Take out the "last;" line if you want it to keep searching after it finds one. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>