Wednesday, 9 April 2014

Perl Conditional Statements..



Perl Conditional Statements - IF...ELSE

Perl conditional statements helps in decision making which require the programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
The number 0, the strings '0' and "" , the empty list () , and undef are all false in a boolean context and all other values are true. Negation of a true value by ! Or not returns a special false value.
Perl programming language provides following types of conditional statements.
Statement
Description
if statement
An if statement consists of a Boolean expression followed by one or more statements.
if...else statement
An if statement can be followed by an optional else statement.
if...elsif...else statement
An if statement can be followed by an optional elsif statement and then by an optional else statement.
unless statement
An unless statement consists of a Boolean expression followed by one or more statements.
unless...else statement
An unless statement can be followed by an optional else statement.
unless...elsif..else statement
An unless statement can be followed by an optional elsif statement and then by an optional else statement.
switch statement
With latest versions of Perl, you can make use of switch statement which allows a simple way of comparing a variable value against various conditions.

No comments: