If, Elsif, and Else in Perl
$gygy="London";
if ($gygy eq "Paris") {
print "The city is Paris. ";
}
elsif ($gygy eq "Tokyo") {
print "The city is Tokyo. ";
}
else {
print "The city is London. ";
}
In plain English:
-The variable we named gygy equals London.
-We say: If gygy equals Paris, print one thing.
-We then say: Else If (elsif) gygy equals Tokyo, print a different thing.
-We then say: or Else! If all else fails, print this other thing.
Copy and Paste Perl Code:
#!/usr/bin/perl
print "Content-type:text.html\n\n";
$gygy="London";
if ($gygy eq "Paris") {
print "The city is Paris. ";
}
elsif ($gygy eq "Tokyo") {
print "The city is Tokyo. ";
}
else {
print "The city is London. ";
}
if ($gygy eq 1) {
print "One";
}
elsif ($gygy eq 2) {
print "Two";
}
else {
print "Three";
}
exit;
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group