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
|
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access