Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://75677]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found