Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: how to quickly tell if number is in an array

by ioannis (Abbot)
on Oct 12, 2005 at 01:25 UTC ( #499336=note: print w/replies, xml ) Need Help??


in reply to how to quickly tell if number is in an array

Fine, you requested an easy method; although, faster methods could be implementd with map or grep, assuming we don't have detailed knowledge if elements are already sorted in the array. Here is on easy method:
my @arr = 1..20 ; my $num = 4; my %h ; @h{@arr} = (undef) x @arr; exists $h{$num} and print qq(Yes, $num exists inside \@arr)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2022-11-28 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?