June 2005
Beginner
480 pages
10h 31m
English
To control whether statements are executed based on a condition in a Perl program, you usually use an if statement. The syntax of an if statement is as follows:
if (expression) block
The statement works like this: If the expression evaluates to true, the block of code is run. If the expression is false, the block of code is not run. Remember that the block includes the braces. Consider this example:
if ( $r == 5 ) {
print 'The value of $r is equal to 5.';
}
The expression being tested is $r == 5. The == symbol is an equality operator. If the two operands on either side—$r and 5—are numerically equal to one another, the expression is considered to be true, and the print statement is executed. If $r is not equal to 5, the ...
Read now
Unlock full access