Perl Expressions

In the expressions used by the conditional statements and while loops I described, various expressions were evaluated to determine how the flow of the program will work. The simplest expressions just evaluate a value and determine whether it is considered to be true or false. Any non-zero number or non-empty string is true; zero, empty strings, and the value undef are false. A simple if statement might evaluate a variable by itself, like this:

$var = undef; 
if ($var) { 
    print "The expression is true.\n"; 
} 

The code inside that if statement would not be executed because undef is always considered to be false. Just as you can evaluate a variable or static value as an expression, you can also evaluate the value returned by a subroutine. ...

Get Sams Teach Yourself CGI in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.