http://perldoc.perl.org/perlcheat.html
http://perldoc.perl.org/perlsyn.html
THREE BUILT IN DATA TYPES
scalar - a single character string, number, or reference to something
array - an ordered list of scalars indexed by numbers, starting with 0
hash - unordered collections of scalars indexed by string key
VARIABLE NAMES
scalar - begins with $, even when referring to a scalar that is part
of an array or hash. The '$' symbol works semantically like
the English word "the" in that is indicates a single value.
EXAMPLES:
$days # the simple scalar value "days"
$days[28] # the 29th element of array @days
$days{'Feb'} # the 'Feb' value from hash %days
$#days # the last index of array @days
arrays - begin with a '@', which works muck like the word "these"
EXAMPLES:
@days # ($days[0], $days[1],... $days[n])
@days[3,4,5] # same as ($days[3],$days[4],$days[5])
@days{'a','c'} # same as ($days{'a'},$days{'c'})
hashes - denoted by '%'
EXAMPLES
%days # (key1, val1, key2, val2 ...)
%mascots # ('Ole Miss', 'Rebels', 'Memphis', 'Tigers' ...)
VARIABLE DECLARATIONS:
Generally optional.
undef - The undefined value a variable holds until it has been assigned
a defined value.
When used as a number: 0
When used as a string: ""
Operators
Comments
Text from a "#" character until the end of the line is a comment,
and is ignored.
Simple Statement
An expression evaluated for its side effects. Must end with a semi-colon.
Truth and Falsehood
The number 0
The strings '0' and ''
The empty list ()
and undef
are all false in a boolean context. All other values are true.
Negation of a true value by ! or not returns a special false value.
When evaluated as a string it is treated as '' ,
but as a number, it is treated as 0.
Statement Modifiers
Any simple statement may optionally be followed by a SINGLE modifier,
just before the terminating semicolon (or block ending).
The possible modifiers are:
if EXPR
unless EXPR
while EXPR
until EXPR
foreach LIST
The EXPR following the modifier is referred to as the "condition". Its truth or falsehood determines how the modifier will behave.
if executes the statement once if and only if the condition is true.
unless is the opposite, it executes the statement unless the condition is true
(i.e., if the condition is false).
foreach is an iterator: it executes the statement once for each
item in the LIST (with $_ aliased to each item in turn).
while repeats the statement while the condition is true.
until does the opposite, it repeats the statement until the
condition is true (or while the condition is false):
Compound Statements
In Perl, a sequence of statements that defines a scope is called a block.
Generally, a block is delimited by curly brackets, also known as braces.
The following compound statements may be used to control flow:
if (EXPR) BLOCK
if (EXPR) BLOCK else BLOCK
if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK
LABEL while (EXPR) BLOCK
LABEL while (EXPR) BLOCK continue BLOCK
LABEL until (EXPR) BLOCK
LABEL until (EXPR) BLOCK continue BLOCK
LABEL for (EXPR; EXPR; EXPR) BLOCK
LABEL foreach VAR (LIST) BLOCK
LABEL foreach VAR (LIST) BLOCK continue BLOCK
LABEL BLOCK continue BLOCK
For Loops
for ($i = 1; $i < 10; $i++) {
...
}
Foreach Loops
The foreach loop iterates over a normal list value
and sets the variable VAR to be each element of the list in turn.
If VAR is omitted, $_ is set to each value.
subroutines - begin with an optional '&' much like the word "do"
chop and chomp (when to use them)
printing output
predefined variables (list some)
Location of Perl
Pattern Matching Example
Perl Cheat Sheet
Packages
my