Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Using IF and OR, I'm sure there is a better way

by cog (Parson)
on Dec 14, 2005 at 23:29 UTC ( [id://516798] : note . print w/replies, xml ) Need Help??


in reply to Using IF and OR, I'm sure there is a better way

For instance:

if (grep { $variable == $_ } (1, 2, 3)) { ... }

Replies are listed 'Best First'.
Re^2: Using IF and OR, I'm sure there is a better way
by monarch (Priest) on Dec 15, 2005 at 04:22 UTC
    This unfortunately is significantly longer to execute than the boolean OR. The grep has to test every value, whereas the if statement uses short-circuit boolean logic to stop testing values as soon as a match is found.
      "significantly"? Maybe a significant factor longer, but if the OP was even considering writing it in a long || ... || ... ||, there aren't enough elements to make it significant in absolute terms.