Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Multiple numeric not or compare in if statement

by hippo (Chancellor)
on Jul 02, 2020 at 09:02 UTC ( #11118797=note: print w/replies, xml ) Need Help??

in reply to Multiple numeric not or compare in if statement

You have good answers already so I'll merely point out 2 things which might make things a little easier for you in general.

Did you know that the || operator has lower precedence than either == or !=? This means that all your inner brackets can go and you can write your conditionals like this:

if ($a == 3 || $a == 77 || $a == 8)

Further, since not has lower precedence than && you could even write the negated one as

if (not $a != 3 && $a != 77 && $a != 8)

Finally, $a and $b are special variables (see perlvar) which means that you would be best to avoid them even in an SSCCE. I'd recommend starting from the other end of the alphabet if you want to use single-character names.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2020-08-10 16:27 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (58 votes). Check out past polls.