And, Or, Equal, Not Equal, Greater Than, Less Than in Perl
Plain Speak / Code
and / &&
or / ||
equals (string) / eq
equals (numeric) / ==
not equal (string) / ne
not equals (numeric) / !=
greater than / >
less than / <
greater than or equal to / >=
less than or equal to / <=
To match or not match more than one
condition:
$ko=3;
$ji="Happy times";
if ($ko < 5 && $ko > 1) { print "YES"; }
- AND && - prints YES because $ko meets both requirements.
if ($ko < 5 || $ko > 10) { print "YES"; }
- OR || - prints YES because $ko matches the first requirement.
if ($ji eq "Happy times") { print "YES"; }
- EQUALS (STRING) eq - prints YES because the string $ji is an exact match.
if ($ko == 3) { print "YES"; }
- EQUALS (NUMBER) == - prints YES because $ko is an exact match.
if ($ji ne "Happy go lucky") { print "YES"; }
- NOT EQUAL (STRING) ne - prints YES because the string $ji doesn't match.
if ($ko != 4) { print "YES"; }
- NOT EQUAL (NUMBER) != - prints YES because $ko isn't equal.
if ($ko >= 3) { print "YES"; }
- GREATER THAN OR EQUAL TO >= - prints YES because $ko is equal or greater.
if ($ko <= 3) { print "YES"; }
- LESS THAN OR EQUAL TO <= - prints YES because $ko is equal or less.
Copy and Paste Perl Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
$ko=3;
$ji="Happy times";
if ($ko < 5 && $ko > 1) { print "YES"; }
if ($ko < 5 || $ko > 10) { print "YES"; }
if ($ji eq "Happy times") { print "YES"; }
if ($ko == 3) { print "YES"; }
if ($ji ne "Happy go lucky") { print "YES"; }
if ($ko != 4) { print "YES"; }
if ($ko >= 3) { print "YES"; }
if ($ko <= 3) { print "YES"; }
exit;
Resources:
If, Elsif, and Else in Perl
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group