Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Answer: How to find out if X is an element in an array?

by atcroft (Abbot)
on Dec 08, 2001 at 12:32 UTC ( [id://130398]=note: print w/replies, xml ) Need Help??


in reply to Re: How to find out if X is an element in an array?
in thread How to find out if X is an element in an array?

This may be simplistic, but what about the following code. Anyone?

# # Given: first value passed is the element to check for # Given: remaining values are the array to check in # sub find_in_list { my ($element, @list2check) = @_; return(scalar(grep($element, @updatelist))); }

Replies are listed 'Best First'.
Re: Re: Answer: How to find out if X is an element in an array?
by juliansnail (Initiate) on Apr 07, 2004 at 00:08 UTC
    Do this or if you search for "1" it'll find "1" as well as "123"...
    return(scalar(grep(/^$element$/, @updatelist)));
    -julian geek

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://130398]
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: (3)
As of 2024-03-29 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found