Perl Tutorials
Using WWW-Mechanize
Perl Basics

Perl Basics

Conditionals

Perl uses standard if/elsif/else statements for conditionals

Examples


$i = 7;
if ($i < 5){
DO SOMETHING
} elsif($i >= 5 && $i < 10) {
DO SOMETHING ELSE
} else {
DO A THIRD THING
}

AND and OR operators

Perl as with many other languages uses the && to signify an and. Also || is used to signal an or. In the following both COND1 and COND2 must be true for the code in the if statement to be executed.


if (COND1 && COND2)

The following statement only one of COND1 and COND2 must be true for the code to be executed.


if (COND1 || COND2)

Conditions may be nested with parenthesis similar to algebraic expressions. Here EITHER COND1 or COND2 must be true and COND3 must be true for the code to be executed.


if ((COND1 || COND2) && COND3)

Arrays and Hashes in Perl <<  1 2 3 4 5  >> Loops in Perl
New Content

Related Information
Using WWW-Mechanize