1. Perl
  2. syntax

Perl syntax

Summarize basic syntax such as if statement and for statement. The Perl grammar stuff is in the syntax article. Please use it as a syntax reference. It also contains an introductory article on syntax.

Syntax check

You can check if Perl's syntax is correct with the "-c" option.

perl -c myapp.pl

String syntax

Introducing the syntax for strings.

Single quote string Character strings that cannot use escape sequences such as variable expansion and line break characters
Double quoted string A string (overwritten) that can use escape sequences such as variable expansion and line break characters
Variable expansion Use variable in strings
Escape sequence Special characters that can be used in strings
Escape sequence of single quoted strings Escape sequence of single quoted strings
Double quote string escape sequence Escape sequence of double quoted strings (overwritten)

Regular expression syntax

The regular expression syntax is explained in detail in the following articles.

Conditional branching syntax

Introducing the syntax for conditional branch.

if Conditional branch
if ~ elsif ~ else Multiple conditional branches
unless Conditional branch that negates the condition
or Conditional branching using OR
goto Unconditional jump
if modifier Postfix if
unless modifier Postfix unless

Please refer to the following article for details on conditional branch using if statement.

Loop syntax

Introduces syntax for control structures such as repetition.


while General-purpose loop syntax
for Repeated statement using index
foreach Process the elements of the array in order
next Jump to the beginning of the next iteration
last Get out of the loop
redo Loop redo
do ~ while Execute the process once before judging the condition of the loop
continue Run just before the condition is reevaluated

Variable syntax

Introduces the syntax for variable declarations.

my Declaration of a lexical variable
our Declaration of a package variable
local Declaration of a local variable
Default variable Default variable $_

Comment syntax

Here's the syntax for writing comments in Perl.

Comments Single-line and multi-line comments

Subroutine syntax

Explains the syntax related to subroutine.

AUTOLOAD Subroutine autoload function

Module syntax

Describes the syntax for modules.

package Package declaration
use Load modules at compile time
require Load the module at run time
do Read the configuration file

Object - oriented syntax

DESTROY Destructor

Perl - specific syntax

Describes the syntax specific to Perl.

Context Scalar context and list context
Boolean value Boolean value in Perl
Type glob Data slot
POD (Plain Old Documentation) How to write a document
List assignment Substitution using a list

Numerical calculation syntax

I will explain the syntax related to numerical calculation.

Numeric literals Numeric representation in Perl

Related information

See the following pages for Perl operators, builtin functions, predefined variable and modules.

Related Informatrion