http://www.perlmonks.org?node_id=1055953


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

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 (Archbishop) on Sep 27, 2013 at 10:52 UTC
    OP doesn't have an array.

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