Command-Line Options
Perl expects any command-line options, also known as
switches or flags , to come first on the command line. The next item is
usually the name of the script, followed by any additional arguments
(often filenames) to be passed into the script. Some of these
additional arguments may be switches, but if so, they must be
processed by the script, since Perl gives up parsing switches as soon
as it sees either a non-switch item or the special --
switch that terminates switch
processing.
A single-character switch with no argument may be combined (bundled) with the switch that follows it, if any. For example:
#!/usr/bin/perl -spi.bak
is the same as:
#!/usr/bin/perl -s -p -i.bak
Perl recognizes the switches listed in Table 3-1.
Table 3-1. Perl switches
Switch | Function | |||
---|---|---|---|---|
-- | Terminates switch processing, even if the next argument starts with a minus. It has no other effect. | |||
-0[octnum] | Specifies the record separator ( | |||
-a | Turns on autosplit mode when used with
-n or -p. An
implicit | |||
-c | Causes Perl to check the syntax of the script and
exit without executing it. More or less equivalent to having
|
Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.