Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: find words in array

by Rudolf (Monk)
on Aug 01, 2012 at 18:42 UTC ( #984874=note: print w/ replies, xml ) Need Help??


in reply to find words in array

Here is an example using pattern matching, if your looking to see if the word is contained within any elements of the array

use v5.14; chomp(my $word = <STDIN>); #get word from command line #chomp removes newline for search foreach my $name(@array){ #loop through names if($name =~ m/$word/i){ #if the word is contained within say $name; # print out the name with a newline (say) } }

otherwise, if your looking for exact maches just do something like this.

use v5.14; chomp(my $word = <STDIN>); foreach my $name(@array){ if($name eq $word){ #if the name equals the word say $name; } }


Comment on Re: find words in array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-12-28 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls