Date: Tue, 03 Jul 2001 15:45:25 +0500 From: Robert Sherman Subject: Re: Finding the subscript of an item in an array... Message-Id: <3B41A245.DFE74F3F@ce.gatech.edu> Weston Cann wrote: > I know that you can find the subscript of an item in an array by > doing something like this: > > my @foo = ('Travis','Bonnie','Flipper','Arnold','Deluxe'); > my $item = 'Flipper'; > > my $index = 0; > my $subscript; > > while($index <= $#foo) > { > if($item eq $foo[$index]) > { $subscript = $index; } > > $index++; > } > > This is OK, but it's sortof bulky. I'm wondering if there's a neat-o > perl idiom/single line kind of way to do the same thing. ---------------------------- @a = qw(flipper travis bonnie arnold deluxe); $i=0; for (@a) {if (/flipper/){ print $i; last; }$i++} ---------------------------- but i'm sure someone can beat that... -rob