The standard grep caveat applies - you could end up doing more work here than you actually wanted.

From the OP: I want to check an array of numbers for a particular value, and if found do something.

Personally, I read this as, "I'm looking for one value to operate upon." But, in general, if you're only looking for a single occurrence of a value, it's better to use a foreach loop (or another explicit loop - while/for/whatever).

The reason is that the grep doesn't stop. So, for example, if the element you're looking for is the first item in your list, the grep solution will still process the entire list looking for additional instances. If you're using one of the looping constructs, you can perform your operation and last out of it when you find the value you're looking for.


In reply to Re^2: checking an array of numbers for a particular value by jimt
in thread checking an array of numbers for a particular value by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.