September 2002
Intermediate to advanced
544 pages
13h 6m
English
Now let’s look at one of the fundamental statements of any language, the if statement. An if statement in Perl evaluates an expression, and if that expression is true, it executes the code within the statement. Here’s an example:
if (2 > 1) {
print "2 is greater than 1.\n";
} As you can see, the expression being evaluated is enclosed in parentheses, and the block of code to be executed appears within braces. If the block of code to be executed consists only of a single statement, you can use a shorthand version of the if statement, which looks like this:
print "2 is greater than 1.\n" if (2 > 1);
That’s basically a more readable way to write an if statement. It acts just as it reads: “Print something if this condition is ...
Read now
Unlock full access