By Alvin Alexander. Last updated: June 28, 2016
Perl equality FAQ: Can you share a list of the Perl equality operators?
Sure. Here's a convenient list of the Perl comparison operators (also known as Perl equality operators, equal, or not equal operators).
The Perl comparison operators are different for numeric and string comparison tests, as you can see here:
Comparison Numeric String Operator Operator Equal to == eq Not equal to != ne Greater than > gt Less than < lt Greater than or equal to >= ge Less than or equal to <= le
The Perl if-then control structure
If you're not familiar with the Perl if-then control structure, here's a quick example to show what a simple Perl if then statement looks like, using a numeric equality comparison:
if ($a == $b) { # true; do something here } else { # false; do something else here }
I prefer my curly braces on separate lines, as shown above, but I'll guess that most Perl developers like them on the same line as their other code, but fortunately it doesn't matter, the Perl interpreter will work either way.