Date: 03 Jul 2001 14:10:45 -0500 From: Ren Maddox Subject: Re: Finding the subscript of an item in an array... Message-Id: On Tue, 03 Jul 2001, iowa_song88.remove_eights_and_this@hotmail.com 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; } { $subscript = $index; last } > $index++; > } Better: for (0..$#foo) { last if $item eq $foo[$_]; } > 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. Well, this normally isn't something you ever need to do when you are solving problems the Perl way. Usually, the answer is, "use a hash." -- Ren Maddox ren@tivoli.com