How to match string inside of array?

S

somebody

If I have an array like:

@arr = ('one', 'two', 'three');

And the varaible $myvar = 'two';


How do I check if $myvar matches 'two' in @arr?

I know I could iterate through the array with
a foreach statement, but was wondering if there
was a more efficient method.

-Thanks
 
J

Jürgen Exner

somebody said:
How do I check if $myvar matches 'two' in @arr?

I know I could iterate through the array with
a foreach statement, but was wondering if there
was a more efficient method.

perldoc -q contains

jue
 
S

somebody

perldoc -q contains

jue


I don't seem to have that. Is it a separate module?

mybox:> perldoc -q contains
No documentation for perl FAQ keyword `contains' found
 
J

Jim Gibson

Jürgen Exner said:
perldoc -q contains

In my version (5.8.6) you have to search for "contained"

FYI to OP: this newsgroup is defunct; try comp.lang.perl.misc in the
future.
 
J

Jürgen Exner

somebody said:
I don't seem to have that. Is it a separate module?

mybox:> perldoc -q contains
No documentation for perl FAQ keyword `contains' found

Strange. I get

E:\>perldoc -q contains
Found in E:\[...]\perlfaq4.pod
How can I tell whether a list or array contains a certain element?


jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top