Literals
- Numeric
- 123 1_234 123.4 5E-10 0xff (hex) 0377 (octal)
- String
-
- 'abc'
- Literal string, no variable interpolation or 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 lowercase/uppercase the following character. \L and \U lowercase/uppercase until a \E is encountered. \Q quotes regular expression characters until a \E is encountered.
`
command`
- Evaluates to the output of the command. Also: qx/command/.
- Array
- (1, 2, 3)
( ) is an empty array.
(1..4) is the same as (1,2,3,4), likewise (
'
a'
..'
z'
).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
- <<identifier
Shell-style "here document."
- Special tokens
- _ _FILE_ _: filename; _ _LINE_ _: line number;
_ _END_ _: end of program; remaining lines can be read using the filehandle DATA.