- publishing free software manuals
Perl Language Reference Manual
by Larry Wall and others
Paperback (6"x9"), 724 pages
ISBN 9781906966027
RRP £29.95 ($39.95)

Sales of this book support The Perl Foundation! Get a printed copy>>>

2.4 Basic syntax overview

A Perl script or program consists of one or more statements. These statements are simply written in the script in a straightforward fashion. There is no need to have a main() function or anything of that kind.

Perl statements end in a semi-colon:

print "Hello, world";

Comments start with a hash symbol and run to the end of the line

# This is a comment

Whitespace is irrelevant:

    "Hello, world"

... except inside quoted strings:

# this would print with a linebreak in the middle
print "Hello

Double quotes or single quotes may be used around literal strings:

print "Hello, world";
print 'Hello, world';

However, only double quotes "interpolate" variables and special characters such as newlines (\n):

print "Hello, $name\n";     # works fine
print 'Hello, $name\n';     # prints $name\n literally

Numbers don't need quotes around them:

print 42;

You can use parentheses for functions' arguments or omit them according to your personal taste. They are only required occasionally to clarify issues of precedence.

print("Hello, world\n");
print "Hello, world\n";

More detailed information about Perl syntax can be found in 4.

ISBN 9781906966027Perl Language Reference ManualSee the print edition