Comparison Operators in Perl

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search

There are 6 comparison operators.

String Operator   Numerical Operator 
eq 	           == 
ne 	           != 
gt 	           > 
lt 	           < 
ge 	           >= 
le 	           <=

eq = equal, gt = greater than. These are case sensative.

Perl actually has two sets of comparison operators - one for comparing numeric values and one for comparing strings.

For testing the equality of two numeric values

if (2 == 2) { print "numbers equal\n"; }

For testing string equality

if ('boots' eq 'boots') { print "strings equal\n"; } 
print "Please enter your private name:\n";
$name = <>;
chomp($name);
if (lc($name) eq "rachel")
{
  print "Your name is Rachel!\n";
}
  else
{
  print "Your name is not Rachel!\n";
}