Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Multiple numeric not or compare in if statement

by jo37 (Pilgrim)
on Jul 02, 2020 at 13:41 UTC ( #11118814=note: print w/replies, xml ) Need Help??


in reply to Multiple numeric not or compare in if statement

The above code is wrong, is bad, works sometimes. I know this is wrong.

You didn't say in which way it should be wrong. It is not wrong, though it might do something different from your expectations.

$sender_transaction_type !~ /3|21/
This is true, if $sender_transaction_type does not contain the digit 3 or the digit sequence 21. For e.g. "35" or "421" it is false. Maybe you expected it to check for equal / not equal, which it doesn't. But it's not wrong.

To check if a string is not in a given set, you may use this expression:

$sender_transaction_type !~ /^(?:3|21)$/
But keep in mind that these are string operations where "3", "3e0" and "3." are all different, contrary to their numerical equality.

Greetings,
-jo

$gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

Replies are listed 'Best First'.
Re^2: Multiple numeric not or compare in if statement
by choroba (Archbishop) on Jul 02, 2020 at 14:38 UTC
    Also note that "2\n" matches the regex. If you don't want that, use \z instead of $.
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

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

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










    Results (58 votes). Check out past polls.

    Notices?