In any programming language, conditional statements are considered as one of the most useful feature. Conditional statements are used, when we need to perform different actions depending on whether the specified condition evaluates to true or false. In perl, we have following conditional statements. Click on the links below to read a statement in detail with example.
- if statement – If statement consists a condition, if the condition evaluates to true then the statements inside “if” execute else they do not execute
- if-else statement – if statement has an optional else statement, if the condition specified in if statement evaluates to true then the statements inside “if” execute else the statements inside “else” execute
- if-elsif-else statement – This is used when we need to check multiple conditions, there can be more than than one “elsif” statements in this construct.
- unless statement – This behaves just opposite to the “if statement”. This statements inside “unless” gets executed when the specified condition returns false.
- unless-else statement – if the condition specified in “unless” statement evaluates to false then the statements inside “unless” execute else the statements inside “else” execute
- unless-elsif-else statement – Used for multiple conditions check
- switch case statement – It is deprecated since Perl 5.10
- given-when-default statement – It is a replacement of switch case
Leave a Reply