|
|
Perl IF ELSIF Conditional Control Function
|
Tutorials

Perl

|
Topic |
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:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
$a = "HIOX";
$b = length($a);
if ($b== 1)
{
print "The string has one character\n";
}
elsif ($b == 2)
{
print "The string has two character\n";
}
else
{
print "The string has many characters\n";
}
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.
|
|
A Note |
|
Simple introduction, basic CGI perl programming codes with examples.
Do send your feedback or suggestions on this tutorial.
This is a copyright content.
|
|
|
|