Perl Cheat Sheet Page 5

ADVERTISEMENT

4. Literals
Numeric: 123
0xff (hex)
0377 (octal).
1_234
123.4
5E-10
String: ’abc’ literal string, no variable interpolation nor escape characters, except
\’ and \\ . Also: q/abc/ . Almost any pair of delimiters can be used
instead of / . . . / .
"abc" Variables are interpolated and escape sequences are processed.
Also: qq/abc/ .
Escape sequences: \t (Tab), \n (Newline), \r (Return), \f
(Formfeed), \b (Backspace), \a (Alarm), \e (Escape), \033 (octal),
\x1b (hex), \c[ (control).
\l and \u lowcase/upcase the following character;
\L and \U lowcase/upcase until a \E is encountered.
\Q quote regexp characters until a \E is encountered.
‘ evaluates to the output of the
.
COMMAND
COMMAND
Also: qx/
COMMAND
/ .
Boolean: Perl has no boolean data type. Anything that evaluates to the null string,
the number zero or the string "0" is considered false, everything else is
true (including strings like "00" !).
Array: (1,2,3) a three member array. () is an empty array.
(1..4) is the same as (1,2,3,4) . Likewise (’abc’..’ade’) .
qw/foo bar . . . / is the same as (’foo’,’bar’, . . . ) .
Array reference: [1,2,3] .
Hash (associative array): (
, . . . ) .
KEY1
,
VAL1
,
KEY2
,
VAL2
Also: (
, . . . ) .
KEY1
=>
VAL1
,
KEY2
=>
VAL2
Hash reference: {
, . . . } .
KEY1
,
VAL1
,
KEY2
,
VAL2
Code reference:
sub
STATEMENTS
{
}
Filehandles: STDIN , STDOUT , STDERR , ARGV , DATA .
User-specified:
HANDLE
, $
VAR
.
Globs: <
PATTERN
> evaluates to all filenames according to the pattern.
Use ‘ <${
VAR
}> ’ or ‘
glob
VAR
’ to glob from a variable.
$
Here-Is: <<
Shell-style ‘here document’.
IDENTIFIER
Special tokens:
_ _FILE_ _ : filename; _ _PACKAGE_ _ : package; _ _LINE_ _ : line
number.
_ _END_ _ : end of program; remaining lines can be read using filehandle
> .
<
DATA
5

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education