Line 52: |
Line 52: |
| === Basic syntax overview === | | === 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. | + | 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 <code>main()</code> function or anything of that kind. |
| | | |
| Perl statements end in a semi-colon: | | Perl statements end in a semi-colon: |
| | | |
− | print "Hello, world"; | + | [http://perldoc.perl.org/functions/print.html print] "Hello, world"; |
| | | |
| Comments start with a hash symbol and run to the end of the line | | Comments start with a hash symbol and run to the end of the line |
Line 64: |
Line 64: |
| Whitespace is irrelevant: | | Whitespace is irrelevant: |
| | | |
− | print | + | [http://perldoc.perl.org/functions/print.html print] |
| "Hello, world" | | "Hello, world" |
| ; | | ; |
Line 71: |
Line 71: |
| | | |
| # this would print with a linebreak in the middle | | # this would print with a linebreak in the middle |
− | print "Hello | + | [http://perldoc.perl.org/functions/print.html print] "Hello |
| world"; | | world"; |
| | | |
| Double quotes or single quotes may be used around literal strings: | | Double quotes or single quotes may be used around literal strings: |
| | | |
− | print "Hello, world"; | + | [http://perldoc.perl.org/functions/print.html print] "Hello, world"; |
− | print 'Hello, world'; | + | [http://perldoc.perl.org/functions/print.html print] 'Hello, world'; |
| | | |
| However, only double quotes "interpolate" variables and special characters such as newlines (\n ): | | However, only double quotes "interpolate" variables and special characters such as newlines (\n ): |
| | | |
− | print "Hello, $name\n"; # works fine | + | [http://perldoc.perl.org/functions/print.html print] "Hello, $name\n"; # works fine |
− | print 'Hello, $name\n'; # prints $name\n literally | + | [http://perldoc.perl.org/functions/print.html print] 'Hello, $name\n'; # prints $name\n literally |
| | | |
| Numbers don't need quotes around them: | | Numbers don't need quotes around them: |
| | | |
− | print 42; | + | [http://perldoc.perl.org/functions/print.html 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. | | 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"); | + | [http://perldoc.perl.org/functions/print.html print]("Hello, world\n"); |
− | print "Hello, world\n"; | + | [http://perldoc.perl.org/functions/print.html print] "Hello, world\n"; |
| + | |
| + | More detailed information about Perl syntax can be found in [http://perldoc.perl.org/perlsyn.html perlsyn]. |
| | | |
− | More detailed information about Perl syntax can be found in perlsyn.
| |
| === Perl variable types === | | === Perl variable types === |
| | | |