Perl by a conditional statement or statements of the execution result (True or False) to determine the execution code block.
Note: number 0 ,, string '0', "", an empty list () and is undef to false , other values are to true . Use front true ! or not false is returned.
Analyzing conditions used:
Perl provides a drop-down of conditional statements:
Statement | description |
---|---|
A if statement consists of a Boolean expression followed by one or more statements. | |
A if statement later be followed by an optional else statement , else statement executes the Boolean expression is false. | |
You can in one if available with an optional rear statements elsif statement , then followed by another else statement . | |
A unless the statement of a Boolean expression followed by one or more statements. | |
A unless the statement after the can with an optional else statement . | |
A unless the statement after the can with an optional elsif statement , then followed by another else statement . | |
In the latest version of Perl, we can use the switch statement. It performs the corresponding code blocks according to the different values. |
if (conditional) {
}
if (conditional) {
}else{
}
if (conditional) {
} Elsif (determination condition) {
} Elsif (determination condition) {
}else{
}
Ternary operator?:
We can use the conditional operator:? To simplify the if ... else statement of operations. Usually in the format:
Exp1 ? Exp2 : Exp3;
If Exp1 expression is true, Exp2 expression evaluates to return it, otherwise return Exp3.
It is shown below:
The implementation of the above program, the output is:
Rookie Tutorial - not the popular website