home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Webmaster in a Nutshell

Previous Chapter 15
Perl Quick Reference
Next
 

15.5 Statements

Every statement is an expression, optionally followed by a modifier, and terminated with a semicolon. The semicolon may be omitted if the statement is the final one in a block.

Execution of expressions can depend on other expressions using one of the modifiers if, unless, while, or until, for example:

expr1 if expr2 ;
expr1 until expr2 ;

The logical operators ||, &&, or ?: also allow conditional execution:

expr1 || expr2 ;
expr1 ? expr2 : expr3 ;

Statements can be combined to form a block when enclosed in {}. blocks may be used to control flow:


if (expr) block [ [ elsif (expr) block...] else block ]

unless (expr) block [ else block ]

[ label: ] while (expr) block [ continue block ]

[ label: ] until (expr) block [ continue block ]

[ label: ] for ( [ expr ] ; [ expr ] ; [ expr ] ) block

[ label: ] foreach var(dagger) (list) block

[ label: ] block [ continue block ]

Program flow can be controlled with:

goto label

Continue execution at the specified label.

last [ label ]

Immediately exits the loop in question. Skips continue block.

next [ label ]

Starts the next iteration of the loop.

redo [ label ]

Restarts the loop block without evaluating the conditional again.

Special forms are:

do block while expr ;
do block until expr ;

which are guaranteed to perform block once before testing expr, and

do block

which effectively turns block into an expression.


Previous Home Next
Operators Book Index Subroutines, Packages, and Modules

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell