Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Multiple numeric not or compare in if statement

by davido (Cardinal)
on Jul 02, 2020 at 16:53 UTC ( #11118832=note: print w/replies, xml ) Need Help??


in reply to Multiple numeric not or compare in if statement

Also worth mentioning: If your list of comparisons starts growing, grep is useful.

if (grep {$a == $_} (3,77,8)) {...} # If any of them match. if (!grep {$a == $_} (3,77,8)) {...} # If none of them match. if (0 == grep {$a == $_} (3,77,8)) {...} # Same as above but more expl +icit. if (3 == grep {$a != $_} (3,77,8)) {...} # Also if none of them match, + but maybe harder to follow.

For a list of three things, it may be more cognitive load to understand. But when the list grows to five or ten things, the grep becomes more palatable.


Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2021-09-28 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?