469,266 Members | 1,768 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

How to match string inside of array?

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
Dec 16 '05 #1
4 16231
somebody wrote:
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
Dec 16 '05 #2
On Fri, 16 Dec 2005 23:19:28 +0000, Jürgen Exner wrote:
somebody wrote:
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

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

mybox:> perldoc -q contains
No documentation for perl FAQ keyword `contains' found
Dec 16 '05 #3
In article <4YHof.11993$fY5.2618@trnddc02>, Jürgen Exner
<ju******@hotmail.com> wrote:
somebody wrote:
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


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.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Dec 16 '05 #4
somebody wrote:
On Fri, 16 Dec 2005 23:19:28 +0000, Jürgen Exner wrote:
somebody wrote:
How do I check if $myvar matches 'two' in @arr?


perldoc -q contains


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
Dec 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by wonil kim | last post: by
4 posts views Thread by Michael Yanowitz | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.