in reply to Re: Multiple condition IF statement using grep and eq
in thread Multiple condition IF statement using grep and eq

Thank you! I knew it would be something simple. That tip is going to be super useful too.
  • Comment on Re^2: Multiple condition IF statement using grep and eq

Replies are listed 'Best First'.
Re^3: Multiple condition IF statement using grep and eq
by Marshall (Canon) on May 04, 2016 at 17:23 UTC
    As further suggestion, move the "cheap test" to the front. Grep implies a foreach loop and is much more "expensive" than a simple equality test. The "if" statement is executed from left to right - don't bother with the grep if the first test fails.

    Also consider the block form of grep:

    if ($inext eq "Global.SAM" and grep{$_ == $F[1]} 73,89,121,101,117,69,77,67,115,81,97,65,113) {}
    "and" is a lower priority operator than "&&" so no extra parens required.