Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by ioannis (Abbot)
on Oct 12, 2005 at 01:25 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-16 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found