Perl Operators

Perl operators, for the most part, are identical to those in JavaScript, with some notable exceptions. First, numeric and string comparison operators are different. This difference can be very frustrating after using JavaScript because it’s easy to forget and use the wrong one. For example, the following script shows the correct way to use numeric and string operators:

						$alpha="Apples"; 
$omega="Oranges"; 
if($alpha ne $omega) { #Uses a string comparison 
      print "They are different \n\n"; 
      } 

The common error in Perl occurs when the programmer uses a line like this when both scalar variables are strings:

						if($alpha != $omega) { #Wrong! 

So, when you write conditional statements in Perl, which are the same as in JavaScript, watch out ...

Get JavaScript Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.