http://qs321.pair.com?node_id=11118814


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 (Cardinal) 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]