Perl IF ELSIF Conditional Control Function
What is If Elsif conditional control function in Perl Programming?
Explanation
In Perl,
If Elsif function in Perl is a conditional control statement, where a set of statement is executed based on a condition.
Syntax:
if (expr1)
{
Statement to be executed
}
elsif (expr2)
{
Statement to be executed
}
else
(
Statement to be executed
)
In the above syntax a set of code is executed if "expr1" is true, else a different set of code is executed based on the condition "expr2" else another set of code is executed.
Example :
#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$a = "HIOX";
$b = length($a);
if ($b== 1)
{
print "The string has one charactern";
}
elsif ($b == 2)
{
print "The string has two charactern";
}
else
{
print "The string has many charactersn";
}
Result :
The string has many characters
In the above example the length of a string "HIOX" is checked and the appropriate result is displayed as the length of the string is not 1 or 2.