Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Foreach loop

by vinoth.ree (Prior)
on Sep 27, 2013 at 10:02 UTC ( #1055953=note: print w/ replies, xml ) Need Help??


in reply to Foreach loop

Use grep with ^ and $ to match exactly 1

if (my ($matched) = grep /^1$/, @array) { print "found it: $matched\n"; }
Update:

Corrected the code as marked by Bloodnok


All is well


Comment on Re: Foreach loop
Select or Download Code
Replies are listed 'Best First'.
Re^2: Foreach loop
by Bloodnok (Vicar) on Sep 27, 2013 at 10:35 UTC
    Hmmm,

    I think you meant to say grep /^1$/, @array

    A user level that continues to overstate my experience :-))

      Oops! Yes Bloodnok, I have not tested it. Thanks.


      All is well
Re^2: Foreach loop
by ww (Bishop) on Sep 27, 2013 at 10:52 UTC
    OP doesn't have an array.

    Did you try this with search values other than '1'?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2015-07-31 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls