in reply to Idiomatic Array Index Search?

I'd probably write it as:
sub arrayindex { my $value = shift; for (0..$#_) { return $_ if $_[$_] eq $value; } return -1; }

Update code changed to reflect MeowChow's comment.

The wrong way to do it would be:
my $index; for $index (0..$#values) { last if $values[$index] eq $value; }

ar0n ]

Replies are listed 'Best First'.
Re: Re: Idiomatic Array Index Search?
by MeowChow (Vicar) on May 27, 2001 at 04:13 UTC
    What if there's no match? That would be indistinguishible from matching the last element.
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print