Plan 9 from Bell Labs’s /usr/web/sources/contrib/gabidiaz/root/sys/man/1perl/perlrun

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  | will give a
.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    nr % 0
.    rr F
.\}
.\"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "PERLRUN 1"
.TH PERLRUN 1 "2002-11-24" "perl v5.8.0" "Perl Programmers Reference Guide"
.SH "NAME"
perlrun \- how to execute the Perl interpreter
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
\&\fBperl\fR	[\ \fB\-CsTtuUWX\fR\ ]
	[\ \fB\-hv\fR\ ]\ [\ \fB\-V\fR[:\fIconfigvar\fR]\ ]
	[\ \fB\-cw\fR\ ]\ [\ \fB\-d\fR[:\fIdebugger\fR]\ ]\ [\ \fB\-D\fR[\fInumber/list\fR]\ ]
	[\ \fB\-pna\fR\ ]\ [\ \fB\-F\fR\fIpattern\fR\ ]\ [\ \fB\-l\fR[\fIoctal\fR]\ ]\ [\ \fB\-0\fR[\fIoctal\fR]\ ]
	[\ \fB\-I\fR\fIdir\fR\ ]\ [\ \fB\-m\fR[\fB\-\fR]\fImodule\fR\ ]\ [\ \fB\-M\fR[\fB\-\fR]\fI'module...'\fR\ ]
	[\ \fB\-P\fR\ ]
	[\ \fB\-S\fR\ ]
	[\ \fB\-x\fR[\fIdir\fR]\ ]
	[\ \fB\-i\fR[\fIextension\fR]\ ]
	[\ \fB\-e\fR\ \fI'command'\fR\ ]\ [\ \fB\-\-\fR\ ]\ [\ \fIprogramfile\fR\ ]\ [\ \fIargument\fR\ ]...
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The normal way to run a Perl program is by making it directly
executable, or else by passing the name of the source file as an
argument on the command line.  (An interactive Perl environment
is also possible\*(--see perldebug for details on how to do that.)
Upon startup, Perl looks for your program in one of the following
places:
.IP "1." 4
Specified line by line via \fB\-e\fR switches on the command line.
.IP "2." 4
Contained in the file specified by the first filename on the command line.
(Note that systems supporting the #! notation invoke interpreters this
way. See \*(L"Location of Perl\*(R".)
.IP "3." 4
Passed in implicitly via standard input.  This works only if there are
no filename arguments\*(--to pass arguments to a STDIN-read program you
must explicitly specify a \*(L"\-\*(R" for the program name.
.PP
With methods 2 and 3, Perl starts parsing the input file from the
beginning, unless you've specified a \fB\-x\fR switch, in which case it
scans for the first line starting with #! and containing the word
\&\*(L"perl\*(R", and starts there instead.  This is useful for running a program
embedded in a larger message.  (In this case you would indicate the end
of the program using the \f(CW\*(C`_\|_END_\|_\*(C'\fR token.)
.PP
The #! line is always examined for switches as the line is being
parsed.  Thus, if you're on a machine that allows only one argument
with the #! line, or worse, doesn't even recognize the #! line, you
still can get consistent switch behavior regardless of how Perl was
invoked, even if \fB\-x\fR was used to find the beginning of the program.
.PP
Because historically some operating systems silently chopped off
kernel interpretation of the #! line after 32 characters, some
switches may be passed in on the command line, and some may not;
you could even get a \*(L"\-\*(R" without its letter, if you're not careful.
You probably want to make sure that all your switches fall either
before or after that 32\-character boundary.  Most switches don't
actually care if they're processed redundantly, but getting a \*(L"\-\*(R"
instead of a complete switch could cause Perl to try to execute
standard input instead of your program.  And a partial \fB\-I\fR switch
could also cause odd results.
.PP
Some switches do care if they are processed twice, for instance
combinations of \fB\-l\fR and \fB\-0\fR.  Either put all the switches after
the 32\-character boundary (if applicable), or replace the use of
\&\fB\-0\fR\fIdigits\fR by \f(CW\*(C`BEGIN{ $/ = "\e0digits"; }\*(C'\fR.
.PP
Parsing of the #! switches starts wherever \*(L"perl\*(R" is mentioned in the line.
The sequences \*(L"\-*\*(R" and \*(L"\- \*(R" are specifically ignored so that you could,
if you were so inclined, say
.PP
.Vb 3
\&    #!/bin/sh -- # -*- perl -*- -p
\&    eval 'exec perl -wS $0 ${1+"$@"}'
\&        if $running_under_some_shell;
.Ve
.PP
to let Perl see the \fB\-p\fR switch.
.PP
A similar trick involves the \fBenv\fR program, if you have it.
.PP
.Vb 1
\&    #!/usr/bin/env perl
.Ve
.PP
The examples above use a relative path to the perl interpreter,
getting whatever version is first in the user's path.  If you want
a specific version of Perl, say, perl5.005_57, you should place
that directly in the #! line's path.
.PP
If the #! line does not contain the word \*(L"perl\*(R", the program named after
the #! is executed instead of the Perl interpreter.  This is slightly
bizarre, but it helps people on machines that don't do #!, because they
can tell a program that their \s-1SHELL\s0 is \fI/usr/bin/perl\fR, and Perl will then
dispatch the program to the correct interpreter for them.
.PP
After locating your program, Perl compiles the entire program to an
internal form.  If there are any compilation errors, execution of the
program is not attempted.  (This is unlike the typical shell script,
which might run part-way through before finding a syntax error.)
.PP
If the program is syntactically correct, it is executed.  If the program
runs off the end without hitting an \fIexit()\fR or \fIdie()\fR operator, an implicit
\&\f(CWexit(0)\fR is provided to indicate successful completion.
.Sh "#! and quoting on non-Unix systems"
.IX Subsection "#! and quoting on non-Unix systems"
Unix's #! technique can be simulated on other systems:
.IP "\s-1OS/2\s0" 4
.IX Item "OS/2"
Put
.Sp
.Vb 1
\&    extproc perl -S -your_switches
.Ve
.Sp
as the first line in \f(CW\*(C`*.cmd\*(C'\fR file (\fB\-S\fR due to a bug in cmd.exe's
`extproc' handling).
.IP "MS-DOS" 4
.IX Item "MS-DOS"
Create a batch file to run your program, and codify it in
\&\f(CW\*(C`ALTERNATIVE_SHEBANG\*(C'\fR (see the \fIdosish.h\fR file in the source
distribution for more information).
.IP "Win95/NT" 4
.IX Item "Win95/NT"
The Win95/NT installation, when using the ActiveState installer for Perl,
will modify the Registry to associate the \fI.pl\fR extension with the perl
interpreter.  If you install Perl by other means (including building from
the sources), you may have to modify the Registry yourself.  Note that
this means you can no longer tell the difference between an executable
Perl program and a Perl library file.
.IP "Macintosh" 4
.IX Item "Macintosh"
A Macintosh perl program will have the appropriate Creator and
Type, so that double-clicking them will invoke the perl application.
.IP "\s-1VMS\s0" 4
.IX Item "VMS"
Put
.Sp
.Vb 2
\&    $ perl -mysw 'f$env("procedure")' 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8' !
\&    $ exit++ + ++$status != 0 and $exit = $status = undef;
.Ve
.Sp
at the top of your program, where \fB\-mysw\fR are any command line switches you
want to pass to Perl.  You can now invoke the program directly, by saying
\&\f(CW\*(C`perl program\*(C'\fR, or as a \s-1DCL\s0 procedure, by saying \f(CW@program\fR (or implicitly
via \fI\s-1DCL$PATH\s0\fR by just using the name of the program).
.Sp
This incantation is a bit much to remember, but Perl will display it for
you if you say \f(CW\*(C`perl "\-V:startperl"\*(C'\fR.
.PP
Command-interpreters on non-Unix systems have rather different ideas
on quoting than Unix shells.  You'll need to learn the special
characters in your command-interpreter (\f(CW\*(C`*\*(C'\fR, \f(CW\*(C`\e\*(C'\fR and \f(CW\*(C`"\*(C'\fR are
common) and how to protect whitespace and these characters to run
one-liners (see \fB\-e\fR below).
.PP
On some systems, you may have to change single-quotes to double ones,
which you must \fInot\fR do on Unix or Plan 9 systems.  You might also
have to change a single % to a %%.
.PP
For example:
.PP
.Vb 2
\&    # Unix
\&    perl -e 'print "Hello world\en"'
.Ve
.PP
.Vb 2
\&    # MS-DOS, etc.
\&    perl -e "print \e"Hello world\en\e""
.Ve
.PP
.Vb 3
\&    # Macintosh
\&    print "Hello world\en"
\&     (then Run "Myscript" or Shift-Command-R)
.Ve
.PP
.Vb 2
\&    # VMS
\&    perl -e "print ""Hello world\en"""
.Ve
.PP
The problem is that none of this is reliable: it depends on the
command and it is entirely possible neither works.  If \fB4DOS\fR were
the command shell, this would probably work better:
.PP
.Vb 1
\&    perl -e "print <Ctrl-x>"Hello world\en<Ctrl-x>""
.Ve
.PP
\&\fB\s-1CMD\s0.EXE\fR in Windows \s-1NT\s0 slipped a lot of standard Unix functionality in
when nobody was looking, but just try to find documentation for its
quoting rules.
.PP
Under the Macintosh, it depends which environment you are using.  The MacPerl
shell, or \s-1MPW\s0, is much like Unix shells in its support for several
quoting variants, except that it makes free use of the Macintosh's non-ASCII
characters as control characters.
.PP
There is no general solution to all of this.  It's just a mess.
.Sh "Location of Perl"
.IX Subsection "Location of Perl"
It may seem obvious to say, but Perl is useful only when users can
easily find it.  When possible, it's good for both \fI/usr/bin/perl\fR
and \fI/usr/local/bin/perl\fR to be symlinks to the actual binary.  If
that can't be done, system administrators are strongly encouraged
to put (symlinks to) perl and its accompanying utilities into a
directory typically found along a user's \s-1PATH\s0, or in some other
obvious and convenient place.
.PP
In this documentation, \f(CW\*(C`#!/usr/bin/perl\*(C'\fR on the first line of the program
will stand in for whatever method works on your system.  You are
advised to use a specific path if you care about a specific version.
.PP
.Vb 1
\&    #!/usr/local/bin/perl5.00554
.Ve
.PP
or if you just want to be running at least version, place a statement
like this at the top of your program:
.PP
.Vb 1
\&    use 5.005_54;
.Ve
.Sh "Command Switches"
.IX Subsection "Command Switches"
As with all standard commands, a single-character switch may be
clustered with the following switch, if any.
.PP
.Vb 1
\&    #!/usr/bin/perl -spi.orig   # same as -s -p -i.orig
.Ve
.PP
Switches include:
.IP "\fB\-0\fR[\fIdigits\fR]" 5
.IX Item "-0[digits]"
specifies the input record separator (\f(CW$/\fR) as an octal number.  If there are
no digits, the null character is the separator.  Other switches may
precede or follow the digits.  For example, if you have a version of
\&\fBfind\fR which can print filenames terminated by the null character, you
can say this:
.Sp
.Vb 1
\&    find . -name '*.orig' -print0 | perl -n0e unlink
.Ve
.Sp
The special value 00 will cause Perl to slurp files in paragraph mode.
The value 0777 will cause Perl to slurp files whole because there is no
legal character with that value.
.IP "\fB\-a\fR" 5
.IX Item "-a"
turns on autosplit mode when used with a \fB\-n\fR or \fB\-p\fR.  An implicit
split command to the \f(CW@F\fR array is done as the first thing inside the
implicit while loop produced by the \fB\-n\fR or \fB\-p\fR.
.Sp
.Vb 1
\&    perl -ane 'print pop(@F), "\en";'
.Ve
.Sp
is equivalent to
.Sp
.Vb 4
\&    while (<>) {
\&        @F = split(' ');
\&        print pop(@F), "\en";
\&    }
.Ve
.Sp
An alternate delimiter may be specified using \fB\-F\fR.
.IP "\fB\-C\fR" 5
.IX Item "-C"
enables Perl to use the native wide character APIs on the target system.
The magic variable \f(CW\*(C`${^WIDE_SYSTEM_CALLS}\*(C'\fR reflects the state of
this switch.  See \*(L"${^WIDE_SYSTEM_CALLS}\*(R" in perlvar.
.Sp
This feature is currently only implemented on the Win32 platform.
.IP "\fB\-c\fR" 5
.IX Item "-c"
causes Perl to check the syntax of the program and then exit without
executing it.  Actually, it \fIwill\fR execute \f(CW\*(C`BEGIN\*(C'\fR, \f(CW\*(C`CHECK\*(C'\fR, and
\&\f(CW\*(C`use\*(C'\fR blocks, because these are considered as occurring outside the
execution of your program.  \f(CW\*(C`INIT\*(C'\fR and \f(CW\*(C`END\*(C'\fR blocks, however, will
be skipped.
.IP "\fB\-d\fR" 5
.IX Item "-d"
runs the program under the Perl debugger.  See perldebug.
.IP "\fB\-d:\fR\fIfoo[=bar,baz]\fR" 5
.IX Item "-d:foo[=bar,baz]"
runs the program under the control of a debugging, profiling, or
tracing module installed as Devel::foo. E.g., \fB\-d:DProf\fR executes
the program using the Devel::DProf profiler.  As with the \fB\-M\fR
flag, options may be passed to the Devel::foo package where they
will be received and interpreted by the Devel::foo::import routine.
The comma-separated list of options must follow a \f(CW\*(C`=\*(C'\fR character.
See perldebug.
.IP "\fB\-D\fR\fIletters\fR" 5
.IX Item "-Dletters"
.PD 0
.IP "\fB\-D\fR\fInumber\fR" 5
.IX Item "-Dnumber"
.PD
sets debugging flags.  To watch how it executes your program, use
\&\fB\-Dtls\fR.  (This works only if debugging is compiled into your
Perl.)  Another nice value is \fB\-Dx\fR, which lists your compiled
syntax tree.  And \fB\-Dr\fR displays compiled regular expressions;
the format of the output is explained in perldebguts.
.Sp
As an alternative, specify a number instead of list of letters (e.g.,
\&\fB\-D14\fR is equivalent to \fB\-Dtls\fR):
.Sp
.Vb 20
\&        1  p  Tokenizing and parsing
\&        2  s  Stack snapshots
\&        4  l  Context (loop) stack processing
\&        8  t  Trace execution
\&       16  o  Method and overloading resolution
\&       32  c  String/numeric conversions
\&       64  P  Print profiling info, preprocessor command for -P, source file input state
\&      128  m  Memory allocation
\&      256  f  Format processing
\&      512  r  Regular expression parsing and execution
\&     1024  x  Syntax tree dump
\&     2048  u  Tainting checks
\&     4096  L  Memory leaks (needs -DLEAKTEST when compiling Perl)
\&     8192  H  Hash dump -- usurps values()
\&    16384  X  Scratchpad allocation
\&    32768  D  Cleaning up
\&    65536  S  Thread synchronization
\&   131072  T  Tokenising
\&   262144  R  Include reference counts of dumped variables (eg when using -Ds)
\&   524288  J  Do not s,t,P-debug (Jump over) opcodes within package DB
.Ve
.Sp
All these flags require \fB\-DDEBUGGING\fR when you compile the Perl
executable (but see Devel::Peek, re which may change this).
See the \fI\s-1INSTALL\s0\fR file in the Perl source distribution
for how to do this.  This flag is automatically set if you include \fB\-g\fR
option when \f(CW\*(C`Configure\*(C'\fR asks you about optimizer/debugger flags.
.Sp
If you're just trying to get a print out of each line of Perl code
as it executes, the way that \f(CW\*(C`sh \-x\*(C'\fR provides for shell scripts,
you can't use Perl's \fB\-D\fR switch.  Instead do this
.Sp
.Vb 2
\&  # If you have "env" utility
\&  env=PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program
.Ve
.Sp
.Vb 2
\&  # Bourne shell syntax
\&  $ PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program
.Ve
.Sp
.Vb 2
\&  # csh syntax
\&  % (setenv PERLDB_OPTS "NonStop=1 AutoTrace=1 frame=2"; perl -dS program)
.Ve
.Sp
See perldebug for details and variations.
.IP "\fB\-e\fR \fIcommandline\fR" 5
.IX Item "-e commandline"
may be used to enter one line of program.  If \fB\-e\fR is given, Perl
will not look for a filename in the argument list.  Multiple \fB\-e\fR
commands may be given to build up a multi-line script.  Make sure
to use semicolons where you would in a normal program.
.IP "\fB\-F\fR\fIpattern\fR" 5
.IX Item "-Fpattern"
specifies the pattern to split on if \fB\-a\fR is also in effect.  The
pattern may be surrounded by \f(CW\*(C`//\*(C'\fR, \f(CW""\fR, or \f(CW''\fR, otherwise it will be
put in single quotes.
.IP "\fB\-h\fR" 5
.IX Item "-h"
prints a summary of the options.
.IP "\fB\-i\fR[\fIextension\fR]" 5
.IX Item "-i[extension]"
specifies that files processed by the \f(CW\*(C`<>\*(C'\fR construct are to be
edited in\-place.  It does this by renaming the input file, opening the
output file by the original name, and selecting that output file as the
default for \fIprint()\fR statements.  The extension, if supplied, is used to
modify the name of the old file to make a backup copy, following these
rules:
.Sp
If no extension is supplied, no backup is made and the current file is
overwritten.
.Sp
If the extension doesn't contain a \f(CW\*(C`*\*(C'\fR, then it is appended to the
end of the current filename as a suffix.  If the extension does
contain one or more \f(CW\*(C`*\*(C'\fR characters, then each \f(CW\*(C`*\*(C'\fR is replaced
with the current filename.  In Perl terms, you could think of this
as:
.Sp
.Vb 1
\&    ($backup = $extension) =~ s/\e*/$file_name/g;
.Ve
.Sp
This allows you to add a prefix to the backup file, instead of (or in
addition to) a suffix:
.Sp
.Vb 1
\&    $ perl -pi 'orig_*' -e 's/bar/baz/' fileA   # backup to 'orig_fileA'
.Ve
.Sp
Or even to place backup copies of the original files into another
directory (provided the directory already exists):
.Sp
.Vb 1
\&    $ perl -pi 'old/*.orig' -e 's/bar/baz/' fileA # backup to 'old/fileA.orig'
.Ve
.Sp
These sets of one-liners are equivalent:
.Sp
.Vb 2
\&    $ perl -pi -e 's/bar/baz/' fileA            # overwrite current file
\&    $ perl -pi '*' -e 's/bar/baz/' fileA        # overwrite current file
.Ve
.Sp
.Vb 2
\&    $ perl -pi '.orig' -e 's/bar/baz/' fileA    # backup to 'fileA.orig'
\&    $ perl -pi '*.orig' -e 's/bar/baz/' fileA   # backup to 'fileA.orig'
.Ve
.Sp
From the shell, saying
.Sp
.Vb 1
\&    $ perl -p -i.orig -e "s/foo/bar/; ... "
.Ve
.Sp
is the same as using the program:
.Sp
.Vb 2
\&    #!/usr/bin/perl -pi.orig
\&    s/foo/bar/;
.Ve
.Sp
which is equivalent to
.Sp
.Vb 21
\&    #!/usr/bin/perl
\&    $extension = '.orig';
\&    LINE: while (<>) {
\&        if ($ARGV ne $oldargv) {
\&            if ($extension !~ /\e*/) {
\&                $backup = $ARGV . $extension;
\&            }
\&            else {
\&                ($backup = $extension) =~ s/\e*/$ARGV/g;
\&            }
\&            rename($ARGV, $backup);
\&            open(ARGVOUT, ">$ARGV");
\&            select(ARGVOUT);
\&            $oldargv = $ARGV;
\&        }
\&        s/foo/bar/;
\&    }
\&    continue {
\&        print;  # this prints to original filename
\&    }
\&    select(STDOUT);
.Ve
.Sp
except that the \fB\-i\fR form doesn't need to compare \f(CW$ARGV\fR to \f(CW$oldargv\fR to
know when the filename has changed.  It does, however, use \s-1ARGVOUT\s0 for
the selected filehandle.  Note that \s-1STDOUT\s0 is restored as the default
output filehandle after the loop.
.Sp
As shown above, Perl creates the backup file whether or not any output
is actually changed.  So this is just a fancy way to copy files:
.Sp
.Vb 3
\&    $ perl -p -i '/some/file/path/*' -e 1 file1 file2 file3...
\&or
\&    $ perl -p -i '.orig' -e 1 file1 file2 file3...
.Ve
.Sp
You can use \f(CW\*(C`eof\*(C'\fR without parentheses to locate the end of each input
file, in case you want to append to each file, or reset line numbering
(see example in \*(L"eof\*(R" in perlfunc).
.Sp
If, for a given file, Perl is unable to create the backup file as
specified in the extension then it will skip that file and continue on
with the next one (if it exists).
.Sp
For a discussion of issues surrounding file permissions and \fB\-i\fR,
see \*(L"Why does Perl let me delete read-only files? Why does \-i clobber protected files? Isn't this a bug in Perl?\*(R" in perlfaq5.
.Sp
You cannot use \fB\-i\fR to create directories or to strip extensions from
files.
.Sp
Perl does not expand \f(CW\*(C`~\*(C'\fR in filenames, which is good, since some
folks use it for their backup files:
.Sp
.Vb 1
\&    $ perl -pi~ -e 's/foo/bar/' file1 file2 file3...
.Ve
.Sp
Finally, the \fB\-i\fR switch does not impede execution when no
files are given on the command line.  In this case, no backup is made
(the original file cannot, of course, be determined) and processing
proceeds from \s-1STDIN\s0 to \s-1STDOUT\s0 as might be expected.
.IP "\fB\-I\fR\fIdirectory\fR" 5
.IX Item "-Idirectory"
Directories specified by \fB\-I\fR are prepended to the search path for
modules (\f(CW@INC\fR), and also tells the C preprocessor where to search for
include files.  The C preprocessor is invoked with \fB\-P\fR; by default it
searches /usr/include and /usr/lib/perl.
.IP "\fB\-l\fR[\fIoctnum\fR]" 5
.IX Item "-l[octnum]"
enables automatic line-ending processing.  It has two separate
effects.  First, it automatically chomps \f(CW$/\fR (the input record
separator) when used with \fB\-n\fR or \fB\-p\fR.  Second, it assigns \f(CW\*(C`$\e\*(C'\fR
(the output record separator) to have the value of \fIoctnum\fR so
that any print statements will have that separator added back on.
If \fIoctnum\fR is omitted, sets \f(CW\*(C`$\e\*(C'\fR to the current value of
\&\f(CW$/\fR.  For instance, to trim lines to 80 columns:
.Sp
.Vb 1
\&    perl -lpe 'substr($_, 80) = ""'
.Ve
.Sp
Note that the assignment \f(CW\*(C`$\e = $/\*(C'\fR is done when the switch is processed,
so the input record separator can be different than the output record
separator if the \fB\-l\fR switch is followed by a \fB\-0\fR switch:
.Sp
.Vb 1
\&    gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
.Ve
.Sp
This sets \f(CW\*(C`$\e\*(C'\fR to newline and then sets \f(CW$/\fR to the null character.
.IP "\fB\-m\fR[\fB\-\fR]\fImodule\fR" 5
.IX Item "-m[-]module"
.PD 0
.IP "\fB\-M\fR[\fB\-\fR]\fImodule\fR" 5
.IX Item "-M[-]module"
.IP "\fB\-M\fR[\fB\-\fR]\fI'module ...'\fR" 5
.IX Item "-M[-]'module ...'"
.IP "\fB\-[mM]\fR[\fB\-\fR]\fImodule=arg[,arg]...\fR" 5
.IX Item "-[mM][-]module=arg[,arg]..."
.PD
\&\fB\-m\fR\fImodule\fR executes \f(CW\*(C`use\*(C'\fR \fImodule\fR \f(CW\*(C`();\*(C'\fR before executing your
program.
.Sp
\&\fB\-M\fR\fImodule\fR executes \f(CW\*(C`use\*(C'\fR \fImodule\fR \f(CW\*(C`;\*(C'\fR before executing your
program.  You can use quotes to add extra code after the module name,
e.g., \f(CW'\-Mmodule qw(foo bar)'\fR.
.Sp
If the first character after the \fB\-M\fR or \fB\-m\fR is a dash (\f(CW\*(C`\-\*(C'\fR)
then the 'use' is replaced with 'no'.
.Sp
A little builtin syntactic sugar means you can also say
\&\fB\-mmodule=foo,bar\fR or \fB\-Mmodule=foo,bar\fR as a shortcut for
\&\f(CW'\-Mmodule qw(foo bar)'\fR.  This avoids the need to use quotes when
importing symbols.  The actual code generated by \fB\-Mmodule=foo,bar\fR is
\&\f(CW\*(C`use module split(/,/,q{foo,bar})\*(C'\fR.  Note that the \f(CW\*(C`=\*(C'\fR form
removes the distinction between \fB\-m\fR and \fB\-M\fR.
.IP "\fB\-n\fR" 5
.IX Item "-n"
causes Perl to assume the following loop around your program, which
makes it iterate over filename arguments somewhat like \fBsed \-n\fR or
\&\fBawk\fR:
.Sp
.Vb 4
\&  LINE:
\&    while (<>) {
\&        ...             # your program goes here
\&    }
.Ve
.Sp
Note that the lines are not printed by default.  See \fB\-p\fR to have
lines printed.  If a file named by an argument cannot be opened for
some reason, Perl warns you about it and moves on to the next file.
.Sp
Here is an efficient way to delete all files older than a week:
.Sp
.Vb 1
\&    find . -mtime +7 -print | perl -nle unlink
.Ve
.Sp
This is faster than using the \fB\-exec\fR switch of \fBfind\fR because you don't
have to start a process on every filename found.  It does suffer from
the bug of mishandling newlines in pathnames, which you can fix if
you follow the example under \fB\-0\fR.
.Sp
\&\f(CW\*(C`BEGIN\*(C'\fR and \f(CW\*(C`END\*(C'\fR blocks may be used to capture control before or after
the implicit program loop, just as in \fBawk\fR.
.IP "\fB\-p\fR" 5
.IX Item "-p"
causes Perl to assume the following loop around your program, which
makes it iterate over filename arguments somewhat like \fBsed\fR:
.Sp
.Vb 6
\&  LINE:
\&    while (<>) {
\&        ...             # your program goes here
\&    } continue {
\&        print or die "-p destination: $!\en";
\&    }
.Ve
.Sp
If a file named by an argument cannot be opened for some reason, Perl
warns you about it, and moves on to the next file.  Note that the
lines are printed automatically.  An error occurring during printing is
treated as fatal.  To suppress printing use the \fB\-n\fR switch.  A \fB\-p\fR
overrides a \fB\-n\fR switch.
.Sp
\&\f(CW\*(C`BEGIN\*(C'\fR and \f(CW\*(C`END\*(C'\fR blocks may be used to capture control before or after
the implicit loop, just as in \fBawk\fR.
.IP "\fB\-P\fR" 5
.IX Item "-P"
\&\fB\s-1NOTE:\s0 Use of \-P is strongly discouraged because of its inherent
problems, including poor portability.\fR
.Sp
This option causes your program to be run through the C preprocessor before
compilation by Perl.  Because both comments and \fBcpp\fR directives begin
with the # character, you should avoid starting comments with any words
recognized by the C preprocessor such as \f(CW"if"\fR, \f(CW"else"\fR, or \f(CW"define"\fR.
.Sp
If you're considering using \f(CW\*(C`\-P\*(C'\fR, you might also want to look at the
Filter::cpp module from \s-1CPAN\s0.
.Sp
The problems of \-P include, but are not limited to:
.RS 5
.IP "\(bu" 10
The \f(CW\*(C`#!\*(C'\fR line is stripped, so any switches there don't apply.
.IP "\(bu" 10
A \f(CW\*(C`\-P\*(C'\fR on a \f(CW\*(C`#!\*(C'\fR line doesn't work.
.IP "\(bu" 10
\&\fBAll\fR lines that begin with (whitespace and) a \f(CW\*(C`#\*(C'\fR but
do not look like cpp commands, are stripped, including anything
inside Perl strings, regular expressions, and here-docs .
.IP "\(bu" 10
In some platforms the C preprocessor knows too much: it knows about
the \*(C+ \-style until-end-of-line comments starting with \f(CW"//"\fR.
This will cause problems with common Perl constructs like
.Sp
.Vb 1
\&    s/foo//;
.Ve
.Sp
because after \-P this will became illegal code
.Sp
.Vb 1
\&    s/foo
.Ve
.Sp
The workaround is to use some other quoting separator than \f(CW"/"\fR,
like for example \f(CW"!"\fR:
.Sp
.Vb 1
\&    s!foo!!;
.Ve
.IP "\(bu" 10
It requires not only a working C preprocessor but also a working
\&\fIsed\fR.  If not on \s-1UNIX\s0, you are probably out of luck on this.
.IP "\(bu" 10
Script line numbers are not preserved.
.IP "\(bu" 10
The \f(CW\*(C`\-x\*(C'\fR does not work with \f(CW\*(C`\-P\*(C'\fR.
.RE
.RS 5
.RE
.IP "\fB\-s\fR" 5
.IX Item "-s"
enables rudimentary switch parsing for switches on the command
line after the program name but before any filename arguments (or before
an argument of \fB\-\-\fR).  This means you can have switches with two leading
dashes (\fB\-\-help\fR).  Any switch found there is removed from \f(CW@ARGV\fR and sets the
corresponding variable in the Perl program.  The following program
prints \*(L"1\*(R" if the program is invoked with a \fB\-xyz\fR switch, and \*(L"abc\*(R"
if it is invoked with \fB\-xyz=abc\fR.
.Sp
.Vb 2
\&    #!/usr/bin/perl -s
\&    if ($xyz) { print "$xyz\en" }
.Ve
.Sp
Do note that \fB\-\-help\fR creates the variable ${\-help}, which is not compliant
with \f(CW\*(C`strict refs\*(C'\fR.
.IP "\fB\-S\fR" 5
.IX Item "-S"
makes Perl use the \s-1PATH\s0 environment variable to search for the
program (unless the name of the program contains directory separators).
.Sp
On some platforms, this also makes Perl append suffixes to the
filename while searching for it.  For example, on Win32 platforms,
the \*(L".bat\*(R" and \*(L".cmd\*(R" suffixes are appended if a lookup for the
original name fails, and if the name does not already end in one
of those suffixes.  If your Perl was compiled with \s-1DEBUGGING\s0 turned
on, using the \-Dp switch to Perl shows how the search progresses.
.Sp
Typically this is used to emulate #! startup on platforms that
don't support #!.  This example works on many platforms that
have a shell compatible with Bourne shell:
.Sp
.Vb 3
\&    #!/usr/bin/perl
\&    eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
\&            if $running_under_some_shell;
.Ve
.Sp
The system ignores the first line and feeds the program to \fI/bin/sh\fR,
which proceeds to try to execute the Perl program as a shell script.
The shell executes the second line as a normal shell command, and thus
starts up the Perl interpreter.  On some systems \f(CW$0\fR doesn't always
contain the full pathname, so the \fB\-S\fR tells Perl to search for the
program if necessary.  After Perl locates the program, it parses the
lines and ignores them because the variable \f(CW$running_under_some_shell\fR
is never true.  If the program will be interpreted by csh, you will need
to replace \f(CW\*(C`${1+"$@"}\*(C'\fR with \f(CW$*\fR, even though that doesn't understand
embedded spaces (and such) in the argument list.  To start up sh rather
than csh, some systems may have to replace the #! line with a line
containing just a colon, which will be politely ignored by Perl.  Other
systems can't control that, and need a totally devious construct that
will work under any of \fBcsh\fR, \fBsh\fR, or Perl, such as the following:
.Sp
.Vb 3
\&        eval '(exit $?0)' && eval 'exec perl -wS $0 ${1+"$@"}'
\&        & eval 'exec /usr/bin/perl -wS $0 $argv:q'
\&                if $running_under_some_shell;
.Ve
.Sp
If the filename supplied contains directory separators (i.e., is an
absolute or relative pathname), and if that file is not found,
platforms that append file extensions will do so and try to look
for the file with those extensions added, one by one.
.Sp
On DOS-like platforms, if the program does not contain directory
separators, it will first be searched for in the current directory
before being searched for on the \s-1PATH\s0.  On Unix platforms, the
program will be searched for strictly on the \s-1PATH\s0.
.IP "\fB\-t\fR" 5
.IX Item "-t"
Like \fB\-T\fR, but taint checks will issue warnings rather than fatal
errors.  These warnings can be controlled normally with \f(CW\*(C`no warnings
qw(taint)\*(C'\fR.
.Sp
\&\fB\s-1NOTE:\s0 this is not a substitute for \-T.\fR This is meant only to be
used as a temporary development aid while securing legacy code:
for real production code and for new secure code written from scratch
always use the real \fB\-T\fR.
.IP "\fB\-T\fR" 5
.IX Item "-T"
forces \*(L"taint\*(R" checks to be turned on so you can test them.  Ordinarily
these checks are done only when running setuid or setgid.  It's a
good idea to turn them on explicitly for programs that run on behalf
of someone else whom you might not necessarily trust, such as \s-1CGI\s0
programs or any internet servers you might write in Perl.  See
perlsec for details.  For security reasons, this option must be
seen by Perl quite early; usually this means it must appear early
on the command line or in the #! line for systems which support
that construct.
.IP "\fB\-u\fR" 5
.IX Item "-u"
This obsolete switch causes Perl to dump core after compiling your
program.  You can then in theory take this core dump and turn it
into an executable file by using the \fBundump\fR program (not supplied).
This speeds startup at the expense of some disk space (which you
can minimize by stripping the executable).  (Still, a \*(L"hello world\*(R"
executable comes out to about 200K on my machine.)  If you want to
execute a portion of your program before dumping, use the \fIdump()\fR
operator instead.  Note: availability of \fBundump\fR is platform
specific and may not be available for a specific port of Perl.
.Sp
This switch has been superseded in favor of the new Perl code
generator backends to the compiler.  See B and B::Bytecode
for details.
.IP "\fB\-U\fR" 5
.IX Item "-U"
allows Perl to do unsafe operations.  Currently the only \*(L"unsafe\*(R"
operations are the unlinking of directories while running as superuser,
and running setuid programs with fatal taint checks turned into
warnings.  Note that the \fB\-w\fR switch (or the \f(CW$^W\fR variable) must
be used along with this option to actually \fIgenerate\fR the
taint-check warnings.
.IP "\fB\-v\fR" 5
.IX Item "-v"
prints the version and patchlevel of your perl executable.
.IP "\fB\-V\fR" 5
.IX Item "-V"
prints summary of the major perl configuration values and the current
values of \f(CW@INC\fR.
.IP "\fB\-V:\fR\fIname\fR" 5
.IX Item "-V:name"
Prints to \s-1STDOUT\s0 the value of the named configuration variable.
For example,
.Sp
.Vb 1
\&    $ perl -V:man.dir
.Ve
.Sp
will provide strong clues about what your \s-1MANPATH\s0 variable should
be set to in order to access the Perl documentation.
.IP "\fB\-w\fR" 5
.IX Item "-w"
prints warnings about dubious constructs, such as variable names
that are mentioned only once and scalar variables that are used
before being set, redefined subroutines, references to undefined
filehandles or filehandles opened read-only that you are attempting
to write on, values used as a number that doesn't look like numbers,
using an array as though it were a scalar, if your subroutines
recurse more than 100 deep, and innumerable other things.
.Sp
This switch really just enables the internal \f(CW\*(C`^$W\*(C'\fR variable.  You
can disable or promote into fatal errors specific warnings using
\&\f(CW\*(C`_\|_WARN_\|_\*(C'\fR hooks, as described in perlvar and \*(L"warn\*(R" in perlfunc.
See also perldiag and perltrap.  A new, fine-grained warning
facility is also available if you want to manipulate entire classes
of warnings; see warnings or perllexwarn.
.IP "\fB\-W\fR" 5
.IX Item "-W"
Enables all warnings regardless of \f(CW\*(C`no warnings\*(C'\fR or \f(CW$^W\fR.
See perllexwarn.
.IP "\fB\-X\fR" 5
.IX Item "-X"
Disables all warnings regardless of \f(CW\*(C`use warnings\*(C'\fR or \f(CW$^W\fR.
See perllexwarn.
.IP "\fB\-x\fR \fIdirectory\fR" 5
.IX Item "-x directory"
tells Perl that the program is embedded in a larger chunk of unrelated
\&\s-1ASCII\s0 text, such as in a mail message.  Leading garbage will be
discarded until the first line that starts with #! and contains the
string \*(L"perl\*(R".  Any meaningful switches on that line will be applied.
If a directory name is specified, Perl will switch to that directory
before running the program.  The \fB\-x\fR switch controls only the
disposal of leading garbage.  The program must be terminated with
\&\f(CW\*(C`_\|_END_\|_\*(C'\fR if there is trailing garbage to be ignored (the program
can process any or all of the trailing garbage via the \s-1DATA\s0 filehandle
if desired).
.SH "ENVIRONMENT"
.IX Header "ENVIRONMENT"
.IP "\s-1HOME\s0" 12
.IX Item "HOME"
Used if chdir has no argument.
.IP "\s-1LOGDIR\s0" 12
.IX Item "LOGDIR"
Used if chdir has no argument and \s-1HOME\s0 is not set.
.IP "\s-1PATH\s0" 12
.IX Item "PATH"
Used in executing subprocesses, and in finding the program if \fB\-S\fR is
used.
.IP "\s-1PERL5LIB\s0" 12
.IX Item "PERL5LIB"
A colon-separated list of directories in which to look for Perl library
files before looking in the standard library and the current
directory.  Any architecture-specific directories under the specified
locations are automatically included if they exist.  If \s-1PERL5LIB\s0 is not
defined, \s-1PERLLIB\s0 is used.
.Sp
When running taint checks (either because the program was running setuid
or setgid, or the \fB\-T\fR switch was used), neither variable is used.
The program should instead say:
.Sp
.Vb 1
\&    use lib "/my/directory";
.Ve
.IP "\s-1PERL5OPT\s0" 12
.IX Item "PERL5OPT"
Command-line options (switches).  Switches in this variable are taken
as if they were on every Perl command line.  Only the \fB\-[DIMUdmtw]\fR
switches are allowed.  When running taint checks (because the program
was running setuid or setgid, or the \fB\-T\fR switch was used), this
variable is ignored.  If \s-1PERL5OPT\s0 begins with \fB\-T\fR, tainting will be
enabled, and any subsequent options ignored.
.IP "\s-1PERLIO\s0" 12
.IX Item "PERLIO"
A space (or colon) separated list of PerlIO layers. If perl is built
to use PerlIO system for \s-1IO\s0 (the default) these layers effect perl's \s-1IO\s0.
.Sp
It is conventional to start layer names with a colon e.g. \f(CW\*(C`:perlio\*(C'\fR to
emphasise their similarity to variable \*(L"attributes\*(R". But the code that parses
layer specification strings (which is also used to decode the \s-1PERLIO\s0
environment variable) treats the colon as a separator.
.Sp
The list becomes the default for \fIall\fR perl's \s-1IO\s0. Consequently only built-in
layers can appear in this list, as external layers (such as :\fIencoding()\fR) need
\&\s-1IO\s0 in  order to load them!. See \*(L"open pragma\*(R" for how to add external
encodings as defaults.
.Sp
The layers that it makes sense to include in the \s-1PERLIO\s0 environment
variable are summarised below. For more details see PerlIO.
.RS 12
.IP ":bytes" 8
.IX Item ":bytes"
Turns \fIoff\fR the \f(CW\*(C`:utf8\*(C'\fR flag for the layer below.
Unlikely to be useful in global \s-1PERLIO\s0 environment variable.
.IP ":crlf" 8
.IX Item ":crlf"
A layer that implements DOS/Windows like \s-1CRLF\s0 line endings.
On read converts pairs of \s-1CR\s0,LF to a single \*(L"\en\*(R" newline character.
On write converts each \*(L"\en\*(R" to a \s-1CR\s0,LF pair.
Based on the \f(CW\*(C`:perlio\*(C'\fR layer.
.IP ":mmap" 8
.IX Item ":mmap"
A layer which implements \*(L"reading\*(R" of files by using \f(CW\*(C`mmap()\*(C'\fR to
make (whole) file appear in the process's address space, and then
using that as PerlIO's \*(L"buffer\*(R". This \fImay\fR be faster in certain
circumstances for large files, and may result in less physical memory
use when multiple processes are reading the same file.
.Sp
Files which are not \f(CW\*(C`mmap()\*(C'\fR\-able revert to behaving like the \f(CW\*(C`:perlio\*(C'\fR
layer. Writes also behave like \f(CW\*(C`:perlio\*(C'\fR layer as \f(CW\*(C`mmap()\*(C'\fR for write
needs extra house-keeping (to extend the file) which negates any advantage.
.Sp
The \f(CW\*(C`:mmap\*(C'\fR layer will not exist if platform does not support \f(CW\*(C`mmap()\*(C'\fR.
.IP ":perlio" 8
.IX Item ":perlio"
A from scratch implementation of buffering for PerlIO. Provides fast
access to the buffer for \f(CW\*(C`sv_gets\*(C'\fR which implements perl's readline/<>
and in general attempts to minimize data copying.
.Sp
\&\f(CW\*(C`:perlio\*(C'\fR will insert a \f(CW\*(C`:unix\*(C'\fR layer below itself to do low level \s-1IO\s0.
.IP ":raw" 8
.IX Item ":raw"
Applying the <:raw> layer is equivalent to calling \f(CW\*(C`binmode($fh)\*(C'\fR.
It makes the stream pass each byte as-is without any translation.
In particular \s-1CRLF\s0 translation, and/or :utf8 inuited from locale
are disabled.
.Sp
Arranges for all accesses go straight to the lowest buffered layer provided
by the configration. That is it strips off any layers above that layer.
.Sp
In Perl 5.6 and some books the \f(CW\*(C`:raw\*(C'\fR layer (previously sometimes also
referred to as a \*(L"discipline\*(R") is documented as the inverse of the
\&\f(CW\*(C`:crlf\*(C'\fR layer. That is no longer the case \- other layers which would
alter binary nature of the stream are also disabled.  If you want \s-1UNIX\s0
line endings on a platform that normally does \s-1CRLF\s0 translation, but still
want \s-1UTF\-8\s0 or encoding defaults the appropriate thing to do is to add
\&\f(CW\*(C`:perlio\*(C'\fR to \s-1PERLIO\s0 environment variable.
.IP ":stdio" 8
.IX Item ":stdio"
This layer provides PerlIO interface by wrapping system's \s-1ANSI\s0 C \*(L"stdio\*(R"
library calls. The layer provides both buffering and \s-1IO\s0.
Note that \f(CW\*(C`:stdio\*(C'\fR layer does \fInot\fR do \s-1CRLF\s0 translation even if that
is platforms normal behaviour. You will need a \f(CW\*(C`:crlf\*(C'\fR layer above it
to do that.
.IP ":unix" 8
.IX Item ":unix"
Lowest level layer which provides basic PerlIO operations in terms of
\&\s-1UNIX/POSIX\s0 numeric file descriptor calls
\&\f(CW\*(C`open(), read(), write(), lseek(), close()\*(C'\fR
.IP ":utf8" 8
.IX Item ":utf8"
Turns on a flag on the layer below to tell perl that data sent to the
stream should be converted to perl internal \*(L"utf8\*(R" form and that data from the
stream should be considered as so encoded. On \s-1ASCII\s0 based platforms the
encoding is \s-1UTF\-8\s0 and on \s-1EBCDIC\s0 platforms \s-1UTF\-EBCDIC\s0.
May be useful in \s-1PERLIO\s0 environment variable to make \s-1UTF\-8\s0 the
default. (To turn off that behaviour use \f(CW\*(C`:bytes\*(C'\fR layer.)
.IP ":win32" 8
.IX Item ":win32"
On Win32 platforms this \fIexperimental\fR layer uses native \*(L"handle\*(R" \s-1IO\s0
rather than unix-like numeric file descriptor layer. Known to be
buggy in this release.
.RE
.RS 12
.Sp
On all platforms the default set of layers should give acceptable results.
.Sp
For \s-1UNIX\s0 platforms that will equivalent of \*(L"unix perlio\*(R" or \*(L"stdio\*(R".
Configure is setup to prefer \*(L"stdio\*(R" implementation if system's library
provides for fast access to the buffer, otherwise it uses the \*(L"unix perlio\*(R"
implementation.
.Sp
On Win32 the default in this release is \*(L"unix crlf\*(R". Win32's \*(L"stdio\*(R"
has a number of bugs/mis\-features for perl \s-1IO\s0 which are somewhat
C compiler vendor/version dependent. Using our own \f(CW\*(C`crlf\*(C'\fR layer as
the buffer avoids those issues and makes things more uniform.
The \f(CW\*(C`crlf\*(C'\fR layer provides \s-1CRLF\s0 to/from \*(L"\en\*(R" conversion as well as
buffering.
.Sp
This release uses \f(CW\*(C`unix\*(C'\fR as the bottom layer on Win32 and so still uses C
compiler's numeric file descriptor routines. There is an experimental native
\&\f(CW\*(C`win32\*(C'\fR layer which is expected to be enhanced and should eventually replace
the \f(CW\*(C`unix\*(C'\fR layer.
.RE
.IP "\s-1PERLIO_DEBUG\s0" 12
.IX Item "PERLIO_DEBUG"
If set to the name of a file or device then certain operations of PerlIO
sub-system will be logged to that file (opened as append). Typical uses
are \s-1UNIX:\s0
.Sp
.Vb 1
\&   PERLIO_DEBUG=/dev/tty perl script ...
.Ve
.Sp
and Win32 approximate equivalent:
.Sp
.Vb 2
\&   set PERLIO_DEBUG=CON
\&   perl script ...
.Ve
.IP "\s-1PERLLIB\s0" 12
.IX Item "PERLLIB"
A colon-separated list of directories in which to look for Perl library
files before looking in the standard library and the current directory.
If \s-1PERL5LIB\s0 is defined, \s-1PERLLIB\s0 is not used.
.IP "\s-1PERL5DB\s0" 12
.IX Item "PERL5DB"
The command used to load the debugger code.  The default is:
.Sp
.Vb 1
\&        BEGIN { require 'perl5db.pl' }
.Ve
.IP "\s-1PERL5SHELL\s0 (specific to the Win32 port)" 12
.IX Item "PERL5SHELL (specific to the Win32 port)"
May be set to an alternative shell that perl must use internally for
executing \*(L"backtick\*(R" commands or \fIsystem()\fR.  Default is \f(CW\*(C`cmd.exe /x/c\*(C'\fR
on WindowsNT and \f(CW\*(C`command.com /c\*(C'\fR on Windows95.  The value is considered
to be space\-separated.  Precede any character that needs to be protected
(like a space or backslash) with a backslash.
.Sp
Note that Perl doesn't use \s-1COMSPEC\s0 for this purpose because
\&\s-1COMSPEC\s0 has a high degree of variability among users, leading to
portability concerns.  Besides, perl can use a shell that may not be
fit for interactive use, and setting \s-1COMSPEC\s0 to such a shell may
interfere with the proper functioning of other programs (which usually
look in \s-1COMSPEC\s0 to find a shell fit for interactive use).
.IP "\s-1PERL_DEBUG_MSTATS\s0" 12
.IX Item "PERL_DEBUG_MSTATS"
Relevant only if perl is compiled with the malloc included with the perl
distribution (that is, if \f(CW\*(C`perl \-V:d_mymalloc\*(C'\fR is 'define').
If set, this causes memory statistics to be dumped after execution.  If set
to an integer greater than one, also causes memory statistics to be dumped
after compilation.
.IP "\s-1PERL_DESTRUCT_LEVEL\s0" 12
.IX Item "PERL_DESTRUCT_LEVEL"
Relevant only if your perl executable was built with \fB\-DDEBUGGING\fR,
this controls the behavior of global destruction of objects and other
references.  See \*(L"\s-1PERL_DESTRUCT_LEVEL\s0\*(R" in perlhack for more information.
.IP "\s-1PERL_ENCODING\s0" 12
.IX Item "PERL_ENCODING"
If using the \f(CW\*(C`encoding\*(C'\fR pragma without an explicit encoding name, the
\&\s-1PERL_ENCODING\s0 environment variable is consulted for an encoding name.
.IP "\s-1PERL_ROOT\s0 (specific to the \s-1VMS\s0 port)" 12
.IX Item "PERL_ROOT (specific to the VMS port)"
A translation concealed rooted logical name that contains perl and the
logical device for the \f(CW@INC\fR path on \s-1VMS\s0 only.  Other logical names that
affect perl on \s-1VMS\s0 include \s-1PERLSHR\s0, \s-1PERL_ENV_TABLES\s0, and
\&\s-1SYS$TIMEZONE_DIFFERENTIAL\s0 but are optional and discussed further in
perlvms and in \fI\s-1README\s0.vms\fR in the Perl source distribution.
.IP "\s-1SYS$LOGIN\s0 (specific to the \s-1VMS\s0 port)" 12
.IX Item "SYS$LOGIN (specific to the VMS port)"
Used if chdir has no argument and \s-1HOME\s0 and \s-1LOGDIR\s0 are not set.
.PP
Perl also has environment variables that control how Perl handles data
specific to particular natural languages.  See perllocale.
.PP
Apart from these, Perl uses no other environment variables, except
to make them available to the program being executed, and to child
processes.  However, programs running setuid would do well to execute
the following lines before doing anything else, just to keep people
honest:
.PP
.Vb 3
\&    $ENV{PATH}  = '/bin:/usr/bin';    # or whatever you need
\&    $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
\&    delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
.Ve

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.