Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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
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 studying the Monastery: (5)
As of 2020-08-10 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (58 votes). Check out past polls.

    Notices?