$var |
a simple scalar variable. |
$var[28] |
29th element of array @var. |
$p = \@var |
now $p is a reference to array @var. |
$$p[28] |
29th element of array referenced by $p.
Also, $p->[28]. |
$var[-1] |
last element of array @var. |
$var[$i][$j] |
$jth element of the $ith
element of array @var. |
$var{'Feb'} |
one value from hash (associative array) %var. |
$p = \%var |
now $p is a reference to hash %var. |
$$p{'Feb'} |
a value from hash referenced by $p.
Also, $p->{'Feb'}. |
$#var |
last index of array @var. |
@var |
the entire array; in a scalar context, the number of elements
in the array. |
@var[3,4,5] |
a slice of array @var. |
@var{'a','b'} |
a slice of %var; same as ($var{'a'},$var{'b'}). |
%var |
the entire hash; in a scalar context, true if the
hash has elements. |
$var{'a',1,...} |
emulates a multidimensional array. |
('a'...'z')[4,7,9] |
a slice of an array literal. |
PKG::VAR |
a variable from a package, e.g., $pkg::var,
@pkg::ary. |
\OBJECT |
reference to an object, e.g., \$var, \%hash. |
*NAME |
refers to all objects represented by NAME.
*n1 = *n2 makes n1 an alias for n2.
*n1 = $n2 makes $n1 an alias for $n2. |
You can always use a
** |
|
Exponentiation |
+ - |
* / |
Addition, subtraction, multiplication, division |
% |
|
Modulo division |
& | |
^ |
Bitwise AND, bitwise OR, bitwise exclusive OR |
>> |
<< |
Bitwise shift right, bitwise shift left |
|| |
&& |
Logical OR, logical AND |
. |
|
Concatenation of two strings |
x |
|
Returns a string or array consisting of the left operand
(an array or a string) repeated the number of times specified by the right
operand |
All of the above operators also have an assignment operator,
e.g., .= |
-> |
|
Dereference operator |
\ |
|
Reference (unary) |
! |
~ |
Negation (unary), bitwise complement (unary) |
++ |
-- |
Auto-increment (magical on strings), auto-decrement |
== |
!= |
Numeric equality, inequality |
eq |
ne |
String equality, inequality |
< |
> |
Numeric less than, greater than |
lt |
gt |
String less than, greater than |
<= |
>= |
Numeric less (greater) than or equal to |
le |
ge |
String less (greater) than or equal to |
<=> |
cmp |
Numeric (string) compare. Returns -1, 0, 1. |
=~ |
!~ |
Search pattern, substitution, or translation (negated) |
.. |
|
Range (scalar context) or enumeration (array context) |
?: |
|
Alternation (if-then-else) operator |
, |
|
Comma operator, also list element separator. You can also use =>. |
not |
|
Low-precedence negation |
and |
|
Low-precedence AND |
or |
xor |
Low-precedence OR, exclusive OR |
All Perl functions can be used as list operators, in which case they have
very high or very low precedence, depending on whether you look at the
left or the right side of the operator. Only the operators A "list" is a list of expressions, variables, or lists. An array variable
or an array slice may always be used instead of a list.
Parentheses can be added around the parameter lists to avoid precedence
problems.
Execution of expressions can depend on other expressions using one of
the modifiers if, unless, while or until, for
example:
abs EXPR† |
Returns the absolute value of its operand. |
atan2 Y,X |
Returns the arctangent of Y/X in the
range -pi to pi. |
cos EXPR† |
Returns the cosine of EXPR (expressed
in radians). |
exp EXPR† |
Returns e to the power of EXPR. |
int EXPR† |
Returns the integer portion of EXPR. |
log EXPR† |
Returns natural logarithm (base e) of EXPR. |
rand [ EXPR ] |
Returns a random fractional number between 0 and the value
of EXPR. If EXPR is omitted,
returns a value between 0 and 1. |
sin EXPR† |
Returns the sine of EXPR (expressed
in radians). |
sqrt EXPR† |
Returns the square root of EXPR. |
srand [ EXPR ] |
Sets the random number seed for the rand operator. |
time |
Returns the number of seconds since January 1, 1970. Suitable
for feeding to gmtime and localtime. |
. |
matches an arbitrary character, but not a newline unless
it is a single-line match (see m//s). |
(...) |
groups a series of pattern elements to a single element. |
^ |
matches the beginning of the target. In multiline mode (see
m//m) also matches after every newline character. |
$ |
matches the end of the line. In multiline mode also matches before
every newline character. |
[ ... ] |
denotes a class of characters to match. [^ ... ]
negates the class. |
( ... | ... |
... ) |
matches one of the alternatives. |
(?# TEXT ) |
Comment. |
(?: REGEXP ) |
Like (REGEXP)
but does not make back-references. |
(?= REGEXP ) |
Zero width positive look-ahead assertion. |
(?! REGEXP ) |
Zero width negative look-ahead assertion. |
(? MODIFIER ) |
Embedded pattern-match modifier. MODIFIER can
be one or more of i, m, s, or x. |
Quantified subpatterns match as many times as possible. When followed
with a ? they match the minimum number of times. These
are the quantifiers: |
+ |
matches the preceding pattern element one or more times. |
? |
matches zero or one times. |
* |
matches zero or more times. |
{N,M} |
denotes the minimum N and maximum M
match count. {N} means
exactly N times; {N,}
means at least N times. |
A \ escapes any special meaning of the following character
if non-alphanumeric, but it turns most alphanumeric characters into something
special: |
\w |
matches alphanumeric, including _, \W
matches non-alphanumeric. |
\s |
matches whitespace, \S matches non-whitespace. |
\d |
matches numeric, \D matches non-numeric. |
\A |
matches the beginning of the string, \Z matches the
end. |
\b |
matches word boundaries, \B matches non-boundaries. |
\G |
matches where the previous m//g search left off. |
\n, \r, \f, \t |
etc. have their usual meaning. |
\w, \s and \d |
may be used within character classes, \b denotes backspace
in this context. |
Back-references: |
\1 ... \9 |
refer to matched subexpressions, grouped with (), inside
the match. |
\10 |
and up can also be used if the pattern matches that many subexpressions. |
See also
-r -w -x |
File is readable/writable/executable by effective uid/gid. |
-R -W -X |
File is readable/writable/executable by real uid/gid. |
-o -O |
File is owned by effective/real uid. |
-e -z |
File exists/has zero size. |
-s |
File exists and has non-zero size. Returns the size. |
-f -d |
File is a plain file/a directory. |
-l -S -p |
File is a symbolic link/a socket/a named pipe (FIFO). |
-b -c |
File is a block/character special file. |
-u -g -k |
File has setuid/setgid/sticky bit set. |
-t |
Tests if filehandle (STDIN by default) is
opened to a tty. |
-T -B |
File is a text/non-text (binary) file. -T
and -B return true on a null file, or a file at
EOF when testing a filehandle. |
-M -A -C |
File modification / access / inode-change time. Measured
in days. Value returned reflects the file age at the time the script started.
See also $^T in the section Special
Variables. |
passwd
|
Returns ($name, $passwd,
$uid, $gid, $quota, $comment,
$gcos, $dir, $shell). |
endpwent |
Ends lookup processing. |
getpwend |
Gets next user information. |
getpwnam NAME |
Gets information by name. |
getpwuid UID |
Gets information by user ID. |
setpwent |
Resets lookup processing. |
|
group
|
Returns ($name, $passwd,
$gid, $members). |
endgrent |
Ends lookup processing. |
getgrgid GID |
Gets information by group ID. |
getgrnam NAME |
Gets information by name. |
getgrent |
Gets next information. |
setgrent |
Resets lookup processing. |
|
hosts
|
Returns ($name, $aliases,
$addrtype, $length, @addrs). |
endhostent |
Ends lookup processing. |
gethostbyaddr ADDR, ADDRTYPE |
Gets information by IP address. |
gethostbyname NAME |
Gets information by hostname. |
gethostent |
Gets next host information. |
sethostent STAYOPEN |
Resets lookup processing. |
|
networks
|
Returns ($name, $aliases,
$addrtype, $net). |
endnetent |
Ends lookup processing. |
getnetbyaddr ADDR, TYPE |
Gets information by address and type. |
getnetbyname NAME |
Gets information by network name. |
getnetent |
Gets next network information. |
setnetent STAYOPEN |
Resets lookup processing. |
|
services
|
Returns ($name, $aliases,
$port, $proto). |
endservent |
Ends lookup processing. |
getservbyname NAME, PROTO |
Gets information by service name. |
getservbyport PORT, PROTO |
Gets information by service port. |
getservent |
Gets next service information. |
setservent STAYOPEN |
Resets lookup processing. |
|
protocols
|
Returns ($name, $aliases,
$proto). |
endprotoent |
Ends lookup processing. |
getprotobyname NAME |
Gets information by protocol name. |
getprotobynumber NUMBER |
Gets information by protocol number. |
getprotoent |
Gets next protocol information. |
setprotoent STAYOPEN |
Resets lookup processing. |
The following variables are global and should
be localized in subroutines: |
$_ |
The default input and pattern-searching space. |
$. |
The current input line number of the last filehandle that
was read. |
$/ |
The input record separator, newline by default. May be multicharacter. |
$, |
The output field separator for the print operator. |
$" |
The separator that joins elements of arrays interpolated
in strings. |
$\ |
The output record separator for the print operator. |
$# |
The output format for printed numbers. Deprecated. |
$* |
Set to 1 to do multiline matching within strings. Deprecated,
see the m and s modifiers in section Search
and Replace Functions. |
$? |
The status returned by the last `...`
command, pipe close or system operator. |
$] |
The perl version number, e.g., 5.001. |
$[ |
The index of the first element in an array, and of the first
character in a substring. Default is 0. Deprecated. |
$; |
The subscript separator for multidimensional array emulation.
Default is "\034". |
$! |
If used in a numeric context, yields the current value of
errno. If used in a string context, yields the corresponding error
string. |
$@ |
The Perl error message from the last eval or do
EXPR command. |
$: |
The set of characters after which a string may be broken
to fill continuation fields (starting with ^) in a format. |
$0 |
The name of the file containing the Perl script being executed.
May be assigned to. |
$$ |
The process ID of the currently executing Perl program.
Altered (in the child process) by fork. |
$< |
The real user ID of this process. |
$> |
The effective user ID of this process. |
$( |
The real group ID of this process. |
$) |
The effective group ID of this process. |
$^A |
The accumulator for formline and write operations. |
$^D |
The debug flags as passed to perl using -D. |
$^F |
The highest system file descriptor, ordinarily 2. |
$^I |
In-place edit extension as passed to Perl using -i. |
$^L |
Formfeed character used in formats. |
$^P |
Internal debugging flag. |
$^T |
The time (as delivered by time) when the program
started. This value is used by the file test operators -M,
-A and -C. |
$^W |
The value if the -w option as passed to
Perl. |
$^X |
The name by which the currently executing program was invoked. |
|
The following variables are context dependent
and need not be localized: |
$% |
The current page number of the currently selected output
channel. |
$= |
The page length of the current output channel. Default is
60 lines. |
$- |
The number of lines remaining on the page. |
$~ |
The name of the current report format. |
$^ |
The name of the current top-of-page format. |
$| |
If set to nonzero, forces a flush after every write or print
on the currently selected output channel. Default is 0. |
$ARGV |
The name of the current file when reading from <>. |
|
The following variables are always local to
the current block: |
$& |
The string matched by the last successful pattern match. |
$` |
The string preceding what was matched by the last successful
match. |
$' |
The string following what was matched by the last successful
match. |
$+ |
The last bracket matched by the last search pattern. |
$1...$9... |
Contain the subpatterns from the corresponding sets of parentheses
in the last pattern successfully matched. $10... and up
are only available if the match contained that many subpatterns. |
@ARGV |
Contains the command-line arguments for the script (not
including the command name). |
@EXPORT |
Names the methods a package exports by default. |
@EXPORT_OK |
Names the methods a package can export upon explicit request. |
@INC |
Contains the list of places to look for Perl scripts to
be evaluated by the do FILENAME and require
commands. |
@ISA |
List of base classes of a package. |
@_ |
Parameter array for subroutines. Also used by split
if not in array context. |
%ENV |
Contains the current environment. |
%INC |
List of files that have been included with require
or do. |
%OVERLOAD |
Can be used to overload operators in a package. |
%SIG |
Used to set signal handlers for various signals. |
h |
Prints out a help message. |
T |
Prints a stack trace. |
s |
Single steps. |
n |
Single steps around subroutine call. |
RETURN key |
Repeats last s or n. |
r |
Returns form the current subroutine. |
c [ LINE ] |
Continues (until LINE, or another breakpoint,
or exit). |
p EXPR |
Prints EXPR. |
l [ RANGE ] |
Lists a range of lines. RANGE may be
a number, start-end, start+amount, or a subroutine name. If RANGE
is omitted, lists next window. |
w |
Lists window around current line. |
- |
Lists previous window. |
f FILE |
Switches to FILE and starts listing
it. |
l SUB |
Lists the named subroutine. |
S |
List the names of all subroutines. |
/PATTERN/ |
Searches forward for PATTERN. |
?PATTERN? |
Searches backward for PATTERN. |
b [ LINE [ CONDITION
] ] |
Sets breakpoint at LINE; default is
the current line. |
b SUB [ CONDITION
] |
Sets breakpoint at the subroutine. |
d [ LINE ] |
Deletes breakpoint at the given line. |
D |
Deletes all breakpoints. |
L |
Lists lines that have breakpoints or actions. |
a LINE COMMAND |
Sets an action for line. |
A |
Deletes all line actions. |
< COMMAND |
Sets an action to be executed before every debugger prompt. |
> COMMAND |
Sets an action to be executed before every s,
c or n command. |
V [ PACKAGE
[ VARS ] ] |
Lists all variables in a package. Default package is main. |
X [ VARS ] |
Like V, but assumes current package. |
! [ [-]NUMBER
] |
Re-executes a command. Default is the previous command. |
H [ -NUMBER ] |
Displays the last -NUMBER
commands of more than one letter. |
t |
Toggles trace mode. |
= [ ALIAS VALUE ] |
Sets alias, or lists current aliases. |
q |
Quits. You may also use your EOF key
character. |
COMMAND |
Executes COMMAND as a Perl statement. |