Cartoon Edmund

Home

Calendar

Contact

Knight Vision

Sitemap



Edmund J. Sutcliffe
Thoughtful Solutions, Creatively Implemented and Communicated

Edmund's Perl Quick Reference - 1 2 3 4 5 6 7 8 9
Click here for a printable version of this page.

Conventions

fixed   denotes literal text.
THIS means variable text, i.e., things you must fill in.
THIS† means that THIS will default to $_ if omitted.
word is a keyword, i.e., a word with a special meaning.
RETURN key   denotes pressing a keyboard key.
[...] denotes an optional part.

Command-Line Options

-a
turns on autosplit mode when used with -n or -p. Splits to @F.
-c
checks syntax but does not execute.
-d
runs the script under the debugger. Use -de 0 to start the debugger without a script
-D NUMBER
sets debugging flags.
-e COMMANDLINE
may be used to enter a single line of script. Multiple -e commands may be given to build up a multiline script.
-F REGEXP
specifies a regular expression to split on if -a is in effect.
-iEXT
files processed by the < > construct are to be edited in place.
-IDIR
with -P, tells the C preprocessor where to look for include files. The directory is prepended to @INC.
-l [OCTNUM]
enables automatic line-end processing, e.g., -l013.
-n
assumes an input loop around your script. Lines are not printed.
-p
assumes an input loop around your script. Lines are printed.
 
-P
runs the C preprocessor on the script before compilation by Perl.
-s
interprets -xxx on the command line as a switch and sets the corresponding variable $xxx in the script.
-S
uses the PATH environment variable to search for the script.
-T
forces taint checking.
-u
dumps core after compiling the script. To be used with the undump(1) program (where available).
-U
allows perl to perform unsafe operations.
-v
prints the version and patchlevel of your Perl executable.
-w
prints warnings about possible spelling errors and other error-prone constructs in the script.
-x [DIR]
extracts Perl program from input stream. If DIR is specified, switches to this directory before running the program.
-0VAL
(that's the number zero.) Designates an initial value for the record separator $/. See also -l

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 quote 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.


Cartoon Edmund

Quick Ref

Tech Tips

Travel Tips

Tech News

Images