Perl IF ELSE Conditional Control Function

What is If else Conditional Control function in Perl programming?

Explanation

The If else 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
}
else
(
Statement to be executed
)

In the above syntax a set of statement is executed if "expr1" is true, else a different set of statement is executed that is after the else statement.

Example :


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$a = "HIOX";
$b = length($a);
if ($b== 1)
{
print "The string has one 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.

Ask Questions

Ask Question