Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: how do i find the index of a specific array value?

by hdp (Beadle)
on Apr 26, 2001 at 04:26 UTC ( [id://75677] : note . print w/replies, xml ) Need Help??


in reply to How do I find the index of a specific array value?

For very large arrays where bailing out as soon as a match is found is a win:
my @a = ( 1 .. 1_000_000 ); # some large array my $want = 5843; my $index = 0; ++$index until $a[$index] == $want or $index > $#a;

Replies are listed 'Best First'.
Re: Answer: how do i find the index of a specific array value?
by hdp (Beadle) on Apr 26, 2001 at 08:49 UTC
    The last line should be ++$index until $a[$index] == $want or $want > $#a, and thanks to stephen for pointing this out.