Horje
perl if else Code Example
perl if else
# Basic syntax:
if (condition_1) {  
	print "condition_1 was met\n";  
}  
elsif (condition_2) {  
	print "condition_2 was met\n";  
}  
else {
	print "for everything else, there's Mastercard\n";
}
# Note, some people like to shorten the syntax like this:
if (condition_1) {  
	print "condition_1 was met\n";  
} elsif (condition_2) {  
	print "condition_2 was met\n";  
} else { print "for everything else, there's Mastercard\n";}

# Example usage:
my $variable = 3;
if ($variable > 5) {  
	print "Three is greater than 5\n";  
}  
elsif ($variable < -7) {  
	print "Three is less than negative 7\n";  
}  
else {
	print "Apparently 3 falls between -7 and 5\n";
}




14

Related
perl add to array Code Example perl add to array Code Example
perl do while loop Code Example perl do while loop Code Example
perl add key to hash Code Example perl add key to hash Code Example
perl math functions Code Example perl math functions Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9