0

I want to match on fieldA and everything in fieldB as long as it isn't 456:

if ($fieldA==123 && $fieldB!==456)

What is the syntax I should use for fieldB? Is it !== or !=? I've also seen something like !$fieldB==456. It's really the syntax of fieldB that I'm having issues with.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alby
  • 426
  • 2
  • 7
  • 17
  • 2
    Read the [perlop](http://perldoc.perl.org/perlop.html) manual page and search for `!=`. – Sean Apr 12 '16 at 16:27
  • Could you please be clearer for which conditions you'd like the `if` to be entered? – ikegami Apr 12 '16 at 17:03
  • Perhaps the real question is where `!==` came from? [From JavaScript](https://stackoverflow.com/questions/1889260/what-is-the-difference-between-and-operators-in-javascript)? – Peter Mortensen Sep 02 '22 at 21:08

1 Answers1

0

In general you want to use

if ($fieldA == 123 && $fieldB != 456)

If you wanted to negate both you could use the form

unless ($fieldA == 123 && $fieldB == 456)

Which would evaluate to true if both assertions were false.

skarface
  • 910
  • 6
  • 19
  • Skarface: Does your !=456 take into account that I'm trying to compare 456 vs. equal 456? I thought that != means NOT EQUAL just like == means comparison. What I need is NOT COMPARED TO 456. – Alby Apr 12 '16 at 16:38
  • 1
    Not sure what you mean. if (a != 5) will evaluate to true if a is not set to 5. just like if (a == 5) will eavluate to true if a is set to 5. – skarface Apr 12 '16 at 16:40
  • 1
    @Alby: What do you mean by "not compared to"? – choroba Apr 12 '16 at 16:41
  • Thanks skarface. Using != worked. I was assuming that if I needed "==" to compare that I needed a similar !== if I wanted the inverse. – Alby Apr 12 '16 at 17:13
  • Reading `man perlop` would be preferable too just guessing operators. – U. Windl Sep 08 '22 at 12:36