25.3. Basic Perl Syntax
Perl follows a syntax similar to that of the C programming language. Perl syntax can be summed up with a few simple rules:
With few exceptions, code lines should end with a semicolon (;). Notable exceptions to the semicolon rule are lines that end in a block delimiter ({ or }).
Blocks of code (usually under control structures such as functions, if statements, and so on) are enclosed in braces ({ and }).
Explicit declaration of all variables is a good idea, and necessary if using strict data declarations.
The use of functions to delimit code fragments is recommended and increases the ability to execute those fragments independently from one another. (Functions are discussed in the "User-Defined Functions" section, later in this chapter.)
Comments can be inserted in Perl code by prefixing the comment with a pound sign (#) or surrounding the comment with /* and */ pairs. In the former case (#), the comment ends at the next line break. Use the latter case for multiline comments.
Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP 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.