Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man1 / perlrun.1
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "PERLRUN 1"
132.TH PERLRUN 1 "2002-06-08" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134perlrun \- how to execute the Perl interpreter
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137\&\fBperl\fR [\ \fB\-CsTtuUWX\fR\ ]
138 [\ \fB\-hv\fR\ ]\ [\ \fB\-V\fR[:\fIconfigvar\fR]\ ]
139 [\ \fB\-cw\fR\ ]\ [\ \fB\-d\fR[:\fIdebugger\fR]\ ]\ [\ \fB\-D\fR[\fInumber/list\fR]\ ]
140 [\ \fB\-pna\fR\ ]\ [\ \fB\-F\fR\fIpattern\fR\ ]\ [\ \fB\-l\fR[\fIoctal\fR]\ ]\ [\ \fB\-0\fR[\fIoctal\fR]\ ]
141 [\ \fB\-I\fR\fIdir\fR\ ]\ [\ \fB\-m\fR[\fB\-\fR]\fImodule\fR\ ]\ [\ \fB\-M\fR[\fB\-\fR]\fI'module...'\fR\ ]
142 [\ \fB\-P\fR\ ]
143 [\ \fB\-S\fR\ ]
144 [\ \fB\-x\fR[\fIdir\fR]\ ]
145 [\ \fB\-i\fR[\fIextension\fR]\ ]
146 [\ \fB\-e\fR\ \fI'command'\fR\ ]\ [\ \fB\-\-\fR\ ]\ [\ \fIprogramfile\fR\ ]\ [\ \fIargument\fR\ ]...
147.SH "DESCRIPTION"
148.IX Header "DESCRIPTION"
149The normal way to run a Perl program is by making it directly
150executable, or else by passing the name of the source file as an
151argument on the command line. (An interactive Perl environment
152is also possible\*(--see perldebug for details on how to do that.)
153Upon startup, Perl looks for your program in one of the following
154places:
155.IP "1." 4
156Specified line by line via \fB\-e\fR switches on the command line.
157.IP "2." 4
158Contained in the file specified by the first filename on the command line.
159(Note that systems supporting the #! notation invoke interpreters this
160way. See \*(L"Location of Perl\*(R".)
161.IP "3." 4
162Passed in implicitly via standard input. This works only if there are
163no filename arguments\*(--to pass arguments to a STDIN-read program you
164must explicitly specify a \*(L"\-\*(R" for the program name.
165.PP
166With methods 2 and 3, Perl starts parsing the input file from the
167beginning, unless you've specified a \fB\-x\fR switch, in which case it
168scans for the first line starting with #! and containing the word
169\&\*(L"perl\*(R", and starts there instead. This is useful for running a program
170embedded in a larger message. (In this case you would indicate the end
171of the program using the \f(CW\*(C`_\|_END_\|_\*(C'\fR token.)
172.PP
173The #! line is always examined for switches as the line is being
174parsed. Thus, if you're on a machine that allows only one argument
175with the #! line, or worse, doesn't even recognize the #! line, you
176still can get consistent switch behavior regardless of how Perl was
177invoked, even if \fB\-x\fR was used to find the beginning of the program.
178.PP
179Because historically some operating systems silently chopped off
180kernel interpretation of the #! line after 32 characters, some
181switches may be passed in on the command line, and some may not;
182you could even get a \*(L"\-\*(R" without its letter, if you're not careful.
183You probably want to make sure that all your switches fall either
184before or after that 32\-character boundary. Most switches don't
185actually care if they're processed redundantly, but getting a \*(L"\-\*(R"
186instead of a complete switch could cause Perl to try to execute
187standard input instead of your program. And a partial \fB\-I\fR switch
188could also cause odd results.
189.PP
190Some switches do care if they are processed twice, for instance
191combinations of \fB\-l\fR and \fB\-0\fR. Either put all the switches after
192the 32\-character boundary (if applicable), or replace the use of
193\&\fB\-0\fR\fIdigits\fR by \f(CW\*(C`BEGIN{ $/ = "\e0digits"; }\*(C'\fR.
194.PP
195Parsing of the #! switches starts wherever \*(L"perl\*(R" is mentioned in the line.
196The sequences \*(L"\-*\*(R" and \*(L"\- \*(R" are specifically ignored so that you could,
197if you were so inclined, say
198.PP
199.Vb 3
200\& #!/bin/sh -- # -*- perl -*- -p
201\& eval 'exec perl -wS $0 ${1+"$@"}'
202\& if $running_under_some_shell;
203.Ve
204.PP
205to let Perl see the \fB\-p\fR switch.
206.PP
207A similar trick involves the \fBenv\fR program, if you have it.
208.PP
209.Vb 1
210\& #!/usr/bin/env perl
211.Ve
212.PP
213The examples above use a relative path to the perl interpreter,
214getting whatever version is first in the user's path. If you want
215a specific version of Perl, say, perl5.005_57, you should place
216that directly in the #! line's path.
217.PP
218If the #! line does not contain the word \*(L"perl\*(R", the program named after
219the #! is executed instead of the Perl interpreter. This is slightly
220bizarre, but it helps people on machines that don't do #!, because they
221can tell a program that their \s-1SHELL\s0 is \fI/usr/bin/perl\fR, and Perl will then
222dispatch the program to the correct interpreter for them.
223.PP
224After locating your program, Perl compiles the entire program to an
225internal form. If there are any compilation errors, execution of the
226program is not attempted. (This is unlike the typical shell script,
227which might run part-way through before finding a syntax error.)
228.PP
229If the program is syntactically correct, it is executed. If the program
230runs off the end without hitting an \fIexit()\fR or \fIdie()\fR operator, an implicit
231\&\f(CWexit(0)\fR is provided to indicate successful completion.
232.Sh "#! and quoting on non-Unix systems"
233.IX Subsection "#! and quoting on non-Unix systems"
234Unix's #! technique can be simulated on other systems:
235.IP "\s-1OS/2\s0" 4
236.IX Item "OS/2"
237Put
238.Sp
239.Vb 1
240\& extproc perl -S -your_switches
241.Ve
242.Sp
243as the first line in \f(CW\*(C`*.cmd\*(C'\fR file (\fB\-S\fR due to a bug in cmd.exe's
244`extproc' handling).
245.IP "MS-DOS" 4
246.IX Item "MS-DOS"
247Create a batch file to run your program, and codify it in
248\&\f(CW\*(C`ALTERNATIVE_SHEBANG\*(C'\fR (see the \fIdosish.h\fR file in the source
249distribution for more information).
250.IP "Win95/NT" 4
251.IX Item "Win95/NT"
252The Win95/NT installation, when using the ActiveState installer for Perl,
253will modify the Registry to associate the \fI.pl\fR extension with the perl
254interpreter. If you install Perl by other means (including building from
255the sources), you may have to modify the Registry yourself. Note that
256this means you can no longer tell the difference between an executable
257Perl program and a Perl library file.
258.IP "Macintosh" 4
259.IX Item "Macintosh"
260A Macintosh perl program will have the appropriate Creator and
261Type, so that double-clicking them will invoke the perl application.
262.IP "\s-1VMS\s0" 4
263.IX Item "VMS"
264Put
265.Sp
266.Vb 2
267\& $ perl -mysw 'f$env("procedure")' 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8' !
268\& $ exit++ + ++$status != 0 and $exit = $status = undef;
269.Ve
270.Sp
271at the top of your program, where \fB\-mysw\fR are any command line switches you
272want to pass to Perl. You can now invoke the program directly, by saying
273\&\f(CW\*(C`perl program\*(C'\fR, or as a \s-1DCL\s0 procedure, by saying \f(CW@program\fR (or implicitly
274via \fI\s-1DCL$PATH\s0\fR by just using the name of the program).
275.Sp
276This incantation is a bit much to remember, but Perl will display it for
277you if you say \f(CW\*(C`perl "\-V:startperl"\*(C'\fR.
278.PP
279Command-interpreters on non-Unix systems have rather different ideas
280on quoting than Unix shells. You'll need to learn the special
281characters in your command-interpreter (\f(CW\*(C`*\*(C'\fR, \f(CW\*(C`\e\*(C'\fR and \f(CW\*(C`"\*(C'\fR are
282common) and how to protect whitespace and these characters to run
283one-liners (see \fB\-e\fR below).
284.PP
285On some systems, you may have to change single-quotes to double ones,
286which you must \fInot\fR do on Unix or Plan 9 systems. You might also
287have to change a single % to a %%.
288.PP
289For example:
290.PP
291.Vb 2
292\& # Unix
293\& perl -e 'print "Hello world\en"'
294.Ve
295.PP
296.Vb 2
297\& # MS-DOS, etc.
298\& perl -e "print \e"Hello world\en\e""
299.Ve
300.PP
301.Vb 3
302\& # Macintosh
303\& print "Hello world\en"
304\& (then Run "Myscript" or Shift-Command-R)
305.Ve
306.PP
307.Vb 2
308\& # VMS
309\& perl -e "print ""Hello world\en"""
310.Ve
311.PP
312The problem is that none of this is reliable: it depends on the
313command and it is entirely possible neither works. If \fB4DOS\fR were
314the command shell, this would probably work better:
315.PP
316.Vb 1
317\& perl -e "print <Ctrl-x>"Hello world\en<Ctrl-x>""
318.Ve
319.PP
320\&\fB\s-1CMD\s0.EXE\fR in Windows \s-1NT\s0 slipped a lot of standard Unix functionality in
321when nobody was looking, but just try to find documentation for its
322quoting rules.
323.PP
324Under the Macintosh, it depends which environment you are using. The MacPerl
325shell, or \s-1MPW\s0, is much like Unix shells in its support for several
326quoting variants, except that it makes free use of the Macintosh's non-ASCII
327characters as control characters.
328.PP
329There is no general solution to all of this. It's just a mess.
330.Sh "Location of Perl"
331.IX Subsection "Location of Perl"
332It may seem obvious to say, but Perl is useful only when users can
333easily find it. When possible, it's good for both \fI/usr/bin/perl\fR
334and \fI/usr/local/bin/perl\fR to be symlinks to the actual binary. If
335that can't be done, system administrators are strongly encouraged
336to put (symlinks to) perl and its accompanying utilities into a
337directory typically found along a user's \s-1PATH\s0, or in some other
338obvious and convenient place.
339.PP
340In this documentation, \f(CW\*(C`#!/usr/bin/perl\*(C'\fR on the first line of the program
341will stand in for whatever method works on your system. You are
342advised to use a specific path if you care about a specific version.
343.PP
344.Vb 1
345\& #!/usr/local/bin/perl5.00554
346.Ve
347.PP
348or if you just want to be running at least version, place a statement
349like this at the top of your program:
350.PP
351.Vb 1
352\& use 5.005_54;
353.Ve
354.Sh "Command Switches"
355.IX Subsection "Command Switches"
356As with all standard commands, a single-character switch may be
357clustered with the following switch, if any.
358.PP
359.Vb 1
360\& #!/usr/bin/perl -spi.orig # same as -s -p -i.orig
361.Ve
362.PP
363Switches include:
364.IP "\fB\-0\fR[\fIdigits\fR]" 5
365.IX Item "-0[digits]"
366specifies the input record separator (\f(CW$/\fR) as an octal number. If there are
367no digits, the null character is the separator. Other switches may
368precede or follow the digits. For example, if you have a version of
369\&\fBfind\fR which can print filenames terminated by the null character, you
370can say this:
371.Sp
372.Vb 1
373\& find . -name '*.orig' -print0 | perl -n0e unlink
374.Ve
375.Sp
376The special value 00 will cause Perl to slurp files in paragraph mode.
377The value 0777 will cause Perl to slurp files whole because there is no
378legal character with that value.
379.IP "\fB\-a\fR" 5
380.IX Item "-a"
381turns on autosplit mode when used with a \fB\-n\fR or \fB\-p\fR. An implicit
382split command to the \f(CW@F\fR array is done as the first thing inside the
383implicit while loop produced by the \fB\-n\fR or \fB\-p\fR.
384.Sp
385.Vb 1
386\& perl -ane 'print pop(@F), "\en";'
387.Ve
388.Sp
389is equivalent to
390.Sp
391.Vb 4
392\& while (<>) {
393\& @F = split(' ');
394\& print pop(@F), "\en";
395\& }
396.Ve
397.Sp
398An alternate delimiter may be specified using \fB\-F\fR.
399.IP "\fB\-C\fR" 5
400.IX Item "-C"
401enables Perl to use the native wide character APIs on the target system.
402The magic variable \f(CW\*(C`${^WIDE_SYSTEM_CALLS}\*(C'\fR reflects the state of
403this switch. See \*(L"${^WIDE_SYSTEM_CALLS}\*(R" in perlvar.
404.Sp
405This feature is currently only implemented on the Win32 platform.
406.IP "\fB\-c\fR" 5
407.IX Item "-c"
408causes Perl to check the syntax of the program and then exit without
409executing it. Actually, it \fIwill\fR execute \f(CW\*(C`BEGIN\*(C'\fR, \f(CW\*(C`CHECK\*(C'\fR, and
410\&\f(CW\*(C`use\*(C'\fR blocks, because these are considered as occurring outside the
411execution of your program. \f(CW\*(C`INIT\*(C'\fR and \f(CW\*(C`END\*(C'\fR blocks, however, will
412be skipped.
413.IP "\fB\-d\fR" 5
414.IX Item "-d"
415runs the program under the Perl debugger. See perldebug.
416.IP "\fB\-d:\fR\fIfoo[=bar,baz]\fR" 5
417.IX Item "-d:foo[=bar,baz]"
418runs the program under the control of a debugging, profiling, or
419tracing module installed as Devel::foo. E.g., \fB\-d:DProf\fR executes
420the program using the Devel::DProf profiler. As with the \fB\-M\fR
421flag, options may be passed to the Devel::foo package where they
422will be received and interpreted by the Devel::foo::import routine.
423The comma-separated list of options must follow a \f(CW\*(C`=\*(C'\fR character.
424See perldebug.
425.IP "\fB\-D\fR\fIletters\fR" 5
426.IX Item "-Dletters"
427.PD 0
428.IP "\fB\-D\fR\fInumber\fR" 5
429.IX Item "-Dnumber"
430.PD
431sets debugging flags. To watch how it executes your program, use
432\&\fB\-Dtls\fR. (This works only if debugging is compiled into your
433Perl.) Another nice value is \fB\-Dx\fR, which lists your compiled
434syntax tree. And \fB\-Dr\fR displays compiled regular expressions;
435the format of the output is explained in perldebguts.
436.Sp
437As an alternative, specify a number instead of list of letters (e.g.,
438\&\fB\-D14\fR is equivalent to \fB\-Dtls\fR):
439.Sp
440.Vb 20
441\& 1 p Tokenizing and parsing
442\& 2 s Stack snapshots
443\& 4 l Context (loop) stack processing
444\& 8 t Trace execution
445\& 16 o Method and overloading resolution
446\& 32 c String/numeric conversions
447\& 64 P Print profiling info, preprocessor command for -P, source file input state
448\& 128 m Memory allocation
449\& 256 f Format processing
450\& 512 r Regular expression parsing and execution
451\& 1024 x Syntax tree dump
452\& 2048 u Tainting checks
453\& 4096 L Memory leaks (needs -DLEAKTEST when compiling Perl)
454\& 8192 H Hash dump -- usurps values()
455\& 16384 X Scratchpad allocation
456\& 32768 D Cleaning up
457\& 65536 S Thread synchronization
458\& 131072 T Tokenising
459\& 262144 R Include reference counts of dumped variables (eg when using -Ds)
460\& 524288 J Do not s,t,P-debug (Jump over) opcodes within package DB
461.Ve
462.Sp
463All these flags require \fB\-DDEBUGGING\fR when you compile the Perl
464executable (but see Devel::Peek, re which may change this).
465See the \fI\s-1INSTALL\s0\fR file in the Perl source distribution
466for how to do this. This flag is automatically set if you include \fB\-g\fR
467option when \f(CW\*(C`Configure\*(C'\fR asks you about optimizer/debugger flags.
468.Sp
469If you're just trying to get a print out of each line of Perl code
470as it executes, the way that \f(CW\*(C`sh \-x\*(C'\fR provides for shell scripts,
471you can't use Perl's \fB\-D\fR switch. Instead do this
472.Sp
473.Vb 2
474\& # If you have "env" utility
475\& env=PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program
476.Ve
477.Sp
478.Vb 2
479\& # Bourne shell syntax
480\& $ PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program
481.Ve
482.Sp
483.Vb 2
484\& # csh syntax
485\& % (setenv PERLDB_OPTS "NonStop=1 AutoTrace=1 frame=2"; perl -dS program)
486.Ve
487.Sp
488See perldebug for details and variations.
489.IP "\fB\-e\fR \fIcommandline\fR" 5
490.IX Item "-e commandline"
491may be used to enter one line of program. If \fB\-e\fR is given, Perl
492will not look for a filename in the argument list. Multiple \fB\-e\fR
493commands may be given to build up a multi-line script. Make sure
494to use semicolons where you would in a normal program.
495.IP "\fB\-F\fR\fIpattern\fR" 5
496.IX Item "-Fpattern"
497specifies the pattern to split on if \fB\-a\fR is also in effect. The
498pattern may be surrounded by \f(CW\*(C`//\*(C'\fR, \f(CW""\fR, or \f(CW''\fR, otherwise it will be
499put in single quotes.
500.IP "\fB\-h\fR" 5
501.IX Item "-h"
502prints a summary of the options.
503.IP "\fB\-i\fR[\fIextension\fR]" 5
504.IX Item "-i[extension]"
505specifies that files processed by the \f(CW\*(C`<>\*(C'\fR construct are to be
506edited in\-place. It does this by renaming the input file, opening the
507output file by the original name, and selecting that output file as the
508default for \fIprint()\fR statements. The extension, if supplied, is used to
509modify the name of the old file to make a backup copy, following these
510rules:
511.Sp
512If no extension is supplied, no backup is made and the current file is
513overwritten.
514.Sp
515If the extension doesn't contain a \f(CW\*(C`*\*(C'\fR, then it is appended to the
516end of the current filename as a suffix. If the extension does
517contain one or more \f(CW\*(C`*\*(C'\fR characters, then each \f(CW\*(C`*\*(C'\fR is replaced
518with the current filename. In Perl terms, you could think of this
519as:
520.Sp
521.Vb 1
522\& ($backup = $extension) =~ s/\e*/$file_name/g;
523.Ve
524.Sp
525This allows you to add a prefix to the backup file, instead of (or in
526addition to) a suffix:
527.Sp
528.Vb 1
529\& $ perl -pi 'orig_*' -e 's/bar/baz/' fileA # backup to 'orig_fileA'
530.Ve
531.Sp
532Or even to place backup copies of the original files into another
533directory (provided the directory already exists):
534.Sp
535.Vb 1
536\& $ perl -pi 'old/*.orig' -e 's/bar/baz/' fileA # backup to 'old/fileA.orig'
537.Ve
538.Sp
539These sets of one-liners are equivalent:
540.Sp
541.Vb 2
542\& $ perl -pi -e 's/bar/baz/' fileA # overwrite current file
543\& $ perl -pi '*' -e 's/bar/baz/' fileA # overwrite current file
544.Ve
545.Sp
546.Vb 2
547\& $ perl -pi '.orig' -e 's/bar/baz/' fileA # backup to 'fileA.orig'
548\& $ perl -pi '*.orig' -e 's/bar/baz/' fileA # backup to 'fileA.orig'
549.Ve
550.Sp
551From the shell, saying
552.Sp
553.Vb 1
554\& $ perl -p -i.orig -e "s/foo/bar/; ... "
555.Ve
556.Sp
557is the same as using the program:
558.Sp
559.Vb 2
560\& #!/usr/bin/perl -pi.orig
561\& s/foo/bar/;
562.Ve
563.Sp
564which is equivalent to
565.Sp
566.Vb 21
567\& #!/usr/bin/perl
568\& $extension = '.orig';
569\& LINE: while (<>) {
570\& if ($ARGV ne $oldargv) {
571\& if ($extension !~ /\e*/) {
572\& $backup = $ARGV . $extension;
573\& }
574\& else {
575\& ($backup = $extension) =~ s/\e*/$ARGV/g;
576\& }
577\& rename($ARGV, $backup);
578\& open(ARGVOUT, ">$ARGV");
579\& select(ARGVOUT);
580\& $oldargv = $ARGV;
581\& }
582\& s/foo/bar/;
583\& }
584\& continue {
585\& print; # this prints to original filename
586\& }
587\& select(STDOUT);
588.Ve
589.Sp
590except that the \fB\-i\fR form doesn't need to compare \f(CW$ARGV\fR to \f(CW$oldargv\fR to
591know when the filename has changed. It does, however, use \s-1ARGVOUT\s0 for
592the selected filehandle. Note that \s-1STDOUT\s0 is restored as the default
593output filehandle after the loop.
594.Sp
595As shown above, Perl creates the backup file whether or not any output
596is actually changed. So this is just a fancy way to copy files:
597.Sp
598.Vb 3
599\& $ perl -p -i '/some/file/path/*' -e 1 file1 file2 file3...
600\&or
601\& $ perl -p -i '.orig' -e 1 file1 file2 file3...
602.Ve
603.Sp
604You can use \f(CW\*(C`eof\*(C'\fR without parentheses to locate the end of each input
605file, in case you want to append to each file, or reset line numbering
606(see example in \*(L"eof\*(R" in perlfunc).
607.Sp
608If, for a given file, Perl is unable to create the backup file as
609specified in the extension then it will skip that file and continue on
610with the next one (if it exists).
611.Sp
612For a discussion of issues surrounding file permissions and \fB\-i\fR,
613see \*(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.
614.Sp
615You cannot use \fB\-i\fR to create directories or to strip extensions from
616files.
617.Sp
618Perl does not expand \f(CW\*(C`~\*(C'\fR in filenames, which is good, since some
619folks use it for their backup files:
620.Sp
621.Vb 1
622\& $ perl -pi~ -e 's/foo/bar/' file1 file2 file3...
623.Ve
624.Sp
625Finally, the \fB\-i\fR switch does not impede execution when no
626files are given on the command line. In this case, no backup is made
627(the original file cannot, of course, be determined) and processing
628proceeds from \s-1STDIN\s0 to \s-1STDOUT\s0 as might be expected.
629.IP "\fB\-I\fR\fIdirectory\fR" 5
630.IX Item "-Idirectory"
631Directories specified by \fB\-I\fR are prepended to the search path for
632modules (\f(CW@INC\fR), and also tells the C preprocessor where to search for
633include files. The C preprocessor is invoked with \fB\-P\fR; by default it
634searches /usr/include and /usr/lib/perl.
635.IP "\fB\-l\fR[\fIoctnum\fR]" 5
636.IX Item "-l[octnum]"
637enables automatic line-ending processing. It has two separate
638effects. First, it automatically chomps \f(CW$/\fR (the input record
639separator) when used with \fB\-n\fR or \fB\-p\fR. Second, it assigns \f(CW\*(C`$\e\*(C'\fR
640(the output record separator) to have the value of \fIoctnum\fR so
641that any print statements will have that separator added back on.
642If \fIoctnum\fR is omitted, sets \f(CW\*(C`$\e\*(C'\fR to the current value of
643\&\f(CW$/\fR. For instance, to trim lines to 80 columns:
644.Sp
645.Vb 1
646\& perl -lpe 'substr($_, 80) = ""'
647.Ve
648.Sp
649Note that the assignment \f(CW\*(C`$\e = $/\*(C'\fR is done when the switch is processed,
650so the input record separator can be different than the output record
651separator if the \fB\-l\fR switch is followed by a \fB\-0\fR switch:
652.Sp
653.Vb 1
654\& gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
655.Ve
656.Sp
657This sets \f(CW\*(C`$\e\*(C'\fR to newline and then sets \f(CW$/\fR to the null character.
658.IP "\fB\-m\fR[\fB\-\fR]\fImodule\fR" 5
659.IX Item "-m[-]module"
660.PD 0
661.IP "\fB\-M\fR[\fB\-\fR]\fImodule\fR" 5
662.IX Item "-M[-]module"
663.IP "\fB\-M\fR[\fB\-\fR]\fI'module ...'\fR" 5
664.IX Item "-M[-]'module ...'"
665.IP "\fB\-[mM]\fR[\fB\-\fR]\fImodule=arg[,arg]...\fR" 5
666.IX Item "-[mM][-]module=arg[,arg]..."
667.PD
668\&\fB\-m\fR\fImodule\fR executes \f(CW\*(C`use\*(C'\fR \fImodule\fR \f(CW\*(C`();\*(C'\fR before executing your
669program.
670.Sp
671\&\fB\-M\fR\fImodule\fR executes \f(CW\*(C`use\*(C'\fR \fImodule\fR \f(CW\*(C`;\*(C'\fR before executing your
672program. You can use quotes to add extra code after the module name,
673e.g., \f(CW'\-Mmodule qw(foo bar)'\fR.
674.Sp
675If the first character after the \fB\-M\fR or \fB\-m\fR is a dash (\f(CW\*(C`\-\*(C'\fR)
676then the 'use' is replaced with 'no'.
677.Sp
678A little builtin syntactic sugar means you can also say
679\&\fB\-mmodule=foo,bar\fR or \fB\-Mmodule=foo,bar\fR as a shortcut for
680\&\f(CW'\-Mmodule qw(foo bar)'\fR. This avoids the need to use quotes when
681importing symbols. The actual code generated by \fB\-Mmodule=foo,bar\fR is
682\&\f(CW\*(C`use module split(/,/,q{foo,bar})\*(C'\fR. Note that the \f(CW\*(C`=\*(C'\fR form
683removes the distinction between \fB\-m\fR and \fB\-M\fR.
684.IP "\fB\-n\fR" 5
685.IX Item "-n"
686causes Perl to assume the following loop around your program, which
687makes it iterate over filename arguments somewhat like \fBsed \-n\fR or
688\&\fBawk\fR:
689.Sp
690.Vb 4
691\& LINE:
692\& while (<>) {
693\& ... # your program goes here
694\& }
695.Ve
696.Sp
697Note that the lines are not printed by default. See \fB\-p\fR to have
698lines printed. If a file named by an argument cannot be opened for
699some reason, Perl warns you about it and moves on to the next file.
700.Sp
701Here is an efficient way to delete all files older than a week:
702.Sp
703.Vb 1
704\& find . -mtime +7 -print | perl -nle unlink
705.Ve
706.Sp
707This is faster than using the \fB\-exec\fR switch of \fBfind\fR because you don't
708have to start a process on every filename found. It does suffer from
709the bug of mishandling newlines in pathnames, which you can fix if
710you follow the example under \fB\-0\fR.
711.Sp
712\&\f(CW\*(C`BEGIN\*(C'\fR and \f(CW\*(C`END\*(C'\fR blocks may be used to capture control before or after
713the implicit program loop, just as in \fBawk\fR.
714.IP "\fB\-p\fR" 5
715.IX Item "-p"
716causes Perl to assume the following loop around your program, which
717makes it iterate over filename arguments somewhat like \fBsed\fR:
718.Sp
719.Vb 6
720\& LINE:
721\& while (<>) {
722\& ... # your program goes here
723\& } continue {
724\& print or die "-p destination: $!\en";
725\& }
726.Ve
727.Sp
728If a file named by an argument cannot be opened for some reason, Perl
729warns you about it, and moves on to the next file. Note that the
730lines are printed automatically. An error occurring during printing is
731treated as fatal. To suppress printing use the \fB\-n\fR switch. A \fB\-p\fR
732overrides a \fB\-n\fR switch.
733.Sp
734\&\f(CW\*(C`BEGIN\*(C'\fR and \f(CW\*(C`END\*(C'\fR blocks may be used to capture control before or after
735the implicit loop, just as in \fBawk\fR.
736.IP "\fB\-P\fR" 5
737.IX Item "-P"
738\&\fB\s-1NOTE:\s0 Use of \-P is strongly discouraged because of its inherent
739problems, including poor portability.\fR
740.Sp
741This option causes your program to be run through the C preprocessor before
742compilation by Perl. Because both comments and \fBcpp\fR directives begin
743with the # character, you should avoid starting comments with any words
744recognized by the C preprocessor such as \f(CW"if"\fR, \f(CW"else"\fR, or \f(CW"define"\fR.
745.Sp
746If you're considering using \f(CW\*(C`\-P\*(C'\fR, you might also want to look at the
747Filter::cpp module from \s-1CPAN\s0.
748.Sp
749The problems of \-P include, but are not limited to:
750.RS 5
751.IP "\(bu" 10
752The \f(CW\*(C`#!\*(C'\fR line is stripped, so any switches there don't apply.
753.IP "\(bu" 10
754A \f(CW\*(C`\-P\*(C'\fR on a \f(CW\*(C`#!\*(C'\fR line doesn't work.
755.IP "\(bu" 10
756\&\fBAll\fR lines that begin with (whitespace and) a \f(CW\*(C`#\*(C'\fR but
757do not look like cpp commands, are stripped, including anything
758inside Perl strings, regular expressions, and here-docs .
759.IP "\(bu" 10
760In some platforms the C preprocessor knows too much: it knows about
761the \*(C+ \-style until-end-of-line comments starting with \f(CW"//"\fR.
762This will cause problems with common Perl constructs like
763.Sp
764.Vb 1
765\& s/foo//;
766.Ve
767.Sp
768because after \-P this will became illegal code
769.Sp
770.Vb 1
771\& s/foo
772.Ve
773.Sp
774The workaround is to use some other quoting separator than \f(CW"/"\fR,
775like for example \f(CW"!"\fR:
776.Sp
777.Vb 1
778\& s!foo!!;
779.Ve
780.IP "\(bu" 10
781It requires not only a working C preprocessor but also a working
782\&\fIsed\fR. If not on \s-1UNIX\s0, you are probably out of luck on this.
783.IP "\(bu" 10
784Script line numbers are not preserved.
785.IP "\(bu" 10
786The \f(CW\*(C`\-x\*(C'\fR does not work with \f(CW\*(C`\-P\*(C'\fR.
787.RE
788.RS 5
789.RE
790.IP "\fB\-s\fR" 5
791.IX Item "-s"
792enables rudimentary switch parsing for switches on the command
793line after the program name but before any filename arguments (or before
794an argument of \fB\-\-\fR). This means you can have switches with two leading
795dashes (\fB\-\-help\fR). Any switch found there is removed from \f(CW@ARGV\fR and sets the
796corresponding variable in the Perl program. The following program
797prints \*(L"1\*(R" if the program is invoked with a \fB\-xyz\fR switch, and \*(L"abc\*(R"
798if it is invoked with \fB\-xyz=abc\fR.
799.Sp
800.Vb 2
801\& #!/usr/bin/perl -s
802\& if ($xyz) { print "$xyz\en" }
803.Ve
804.Sp
805Do note that \fB\-\-help\fR creates the variable ${\-help}, which is not compliant
806with \f(CW\*(C`strict refs\*(C'\fR.
807.IP "\fB\-S\fR" 5
808.IX Item "-S"
809makes Perl use the \s-1PATH\s0 environment variable to search for the
810program (unless the name of the program contains directory separators).
811.Sp
812On some platforms, this also makes Perl append suffixes to the
813filename while searching for it. For example, on Win32 platforms,
814the \*(L".bat\*(R" and \*(L".cmd\*(R" suffixes are appended if a lookup for the
815original name fails, and if the name does not already end in one
816of those suffixes. If your Perl was compiled with \s-1DEBUGGING\s0 turned
817on, using the \-Dp switch to Perl shows how the search progresses.
818.Sp
819Typically this is used to emulate #! startup on platforms that
820don't support #!. This example works on many platforms that
821have a shell compatible with Bourne shell:
822.Sp
823.Vb 3
824\& #!/usr/bin/perl
825\& eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
826\& if $running_under_some_shell;
827.Ve
828.Sp
829The system ignores the first line and feeds the program to \fI/bin/sh\fR,
830which proceeds to try to execute the Perl program as a shell script.
831The shell executes the second line as a normal shell command, and thus
832starts up the Perl interpreter. On some systems \f(CW$0\fR doesn't always
833contain the full pathname, so the \fB\-S\fR tells Perl to search for the
834program if necessary. After Perl locates the program, it parses the
835lines and ignores them because the variable \f(CW$running_under_some_shell\fR
836is never true. If the program will be interpreted by csh, you will need
837to replace \f(CW\*(C`${1+"$@"}\*(C'\fR with \f(CW$*\fR, even though that doesn't understand
838embedded spaces (and such) in the argument list. To start up sh rather
839than csh, some systems may have to replace the #! line with a line
840containing just a colon, which will be politely ignored by Perl. Other
841systems can't control that, and need a totally devious construct that
842will work under any of \fBcsh\fR, \fBsh\fR, or Perl, such as the following:
843.Sp
844.Vb 3
845\& eval '(exit $?0)' && eval 'exec perl -wS $0 ${1+"$@"}'
846\& & eval 'exec /usr/bin/perl -wS $0 $argv:q'
847\& if $running_under_some_shell;
848.Ve
849.Sp
850If the filename supplied contains directory separators (i.e., is an
851absolute or relative pathname), and if that file is not found,
852platforms that append file extensions will do so and try to look
853for the file with those extensions added, one by one.
854.Sp
855On DOS-like platforms, if the program does not contain directory
856separators, it will first be searched for in the current directory
857before being searched for on the \s-1PATH\s0. On Unix platforms, the
858program will be searched for strictly on the \s-1PATH\s0.
859.IP "\fB\-t\fR" 5
860.IX Item "-t"
861Like \fB\-T\fR, but taint checks will issue warnings rather than fatal
862errors. These warnings can be controlled normally with \f(CW\*(C`no warnings
863qw(taint)\*(C'\fR.
864.Sp
865\&\fB\s-1NOTE:\s0 this is not a substitute for \-T.\fR This is meant only to be
866used as a temporary development aid while securing legacy code:
867for real production code and for new secure code written from scratch
868always use the real \fB\-T\fR.
869.IP "\fB\-T\fR" 5
870.IX Item "-T"
871forces \*(L"taint\*(R" checks to be turned on so you can test them. Ordinarily
872these checks are done only when running setuid or setgid. It's a
873good idea to turn them on explicitly for programs that run on behalf
874of someone else whom you might not necessarily trust, such as \s-1CGI\s0
875programs or any internet servers you might write in Perl. See
876perlsec for details. For security reasons, this option must be
877seen by Perl quite early; usually this means it must appear early
878on the command line or in the #! line for systems which support
879that construct.
880.IP "\fB\-u\fR" 5
881.IX Item "-u"
882This obsolete switch causes Perl to dump core after compiling your
883program. You can then in theory take this core dump and turn it
884into an executable file by using the \fBundump\fR program (not supplied).
885This speeds startup at the expense of some disk space (which you
886can minimize by stripping the executable). (Still, a \*(L"hello world\*(R"
887executable comes out to about 200K on my machine.) If you want to
888execute a portion of your program before dumping, use the \fIdump()\fR
889operator instead. Note: availability of \fBundump\fR is platform
890specific and may not be available for a specific port of Perl.
891.Sp
892This switch has been superseded in favor of the new Perl code
893generator backends to the compiler. See B and B::Bytecode
894for details.
895.IP "\fB\-U\fR" 5
896.IX Item "-U"
897allows Perl to do unsafe operations. Currently the only \*(L"unsafe\*(R"
898operations are the unlinking of directories while running as superuser,
899and running setuid programs with fatal taint checks turned into
900warnings. Note that the \fB\-w\fR switch (or the \f(CW$^W\fR variable) must
901be used along with this option to actually \fIgenerate\fR the
902taint-check warnings.
903.IP "\fB\-v\fR" 5
904.IX Item "-v"
905prints the version and patchlevel of your perl executable.
906.IP "\fB\-V\fR" 5
907.IX Item "-V"
908prints summary of the major perl configuration values and the current
909values of \f(CW@INC\fR.
910.IP "\fB\-V:\fR\fIname\fR" 5
911.IX Item "-V:name"
912Prints to \s-1STDOUT\s0 the value of the named configuration variable.
913For example,
914.Sp
915.Vb 1
916\& $ perl -V:man.dir
917.Ve
918.Sp
919will provide strong clues about what your \s-1MANPATH\s0 variable should
920be set to in order to access the Perl documentation.
921.IP "\fB\-w\fR" 5
922.IX Item "-w"
923prints warnings about dubious constructs, such as variable names
924that are mentioned only once and scalar variables that are used
925before being set, redefined subroutines, references to undefined
926filehandles or filehandles opened read-only that you are attempting
927to write on, values used as a number that doesn't look like numbers,
928using an array as though it were a scalar, if your subroutines
929recurse more than 100 deep, and innumerable other things.
930.Sp
931This switch really just enables the internal \f(CW\*(C`^$W\*(C'\fR variable. You
932can disable or promote into fatal errors specific warnings using
933\&\f(CW\*(C`_\|_WARN_\|_\*(C'\fR hooks, as described in perlvar and \*(L"warn\*(R" in perlfunc.
934See also perldiag and perltrap. A new, fine-grained warning
935facility is also available if you want to manipulate entire classes
936of warnings; see warnings or perllexwarn.
937.IP "\fB\-W\fR" 5
938.IX Item "-W"
939Enables all warnings regardless of \f(CW\*(C`no warnings\*(C'\fR or \f(CW$^W\fR.
940See perllexwarn.
941.IP "\fB\-X\fR" 5
942.IX Item "-X"
943Disables all warnings regardless of \f(CW\*(C`use warnings\*(C'\fR or \f(CW$^W\fR.
944See perllexwarn.
945.IP "\fB\-x\fR \fIdirectory\fR" 5
946.IX Item "-x directory"
947tells Perl that the program is embedded in a larger chunk of unrelated
948\&\s-1ASCII\s0 text, such as in a mail message. Leading garbage will be
949discarded until the first line that starts with #! and contains the
950string \*(L"perl\*(R". Any meaningful switches on that line will be applied.
951If a directory name is specified, Perl will switch to that directory
952before running the program. The \fB\-x\fR switch controls only the
953disposal of leading garbage. The program must be terminated with
954\&\f(CW\*(C`_\|_END_\|_\*(C'\fR if there is trailing garbage to be ignored (the program
955can process any or all of the trailing garbage via the \s-1DATA\s0 filehandle
956if desired).
957.SH "ENVIRONMENT"
958.IX Header "ENVIRONMENT"
959.IP "\s-1HOME\s0" 12
960.IX Item "HOME"
961Used if chdir has no argument.
962.IP "\s-1LOGDIR\s0" 12
963.IX Item "LOGDIR"
964Used if chdir has no argument and \s-1HOME\s0 is not set.
965.IP "\s-1PATH\s0" 12
966.IX Item "PATH"
967Used in executing subprocesses, and in finding the program if \fB\-S\fR is
968used.
969.IP "\s-1PERL5LIB\s0" 12
970.IX Item "PERL5LIB"
971A colon-separated list of directories in which to look for Perl library
972files before looking in the standard library and the current
973directory. Any architecture-specific directories under the specified
974locations are automatically included if they exist. If \s-1PERL5LIB\s0 is not
975defined, \s-1PERLLIB\s0 is used.
976.Sp
977When running taint checks (either because the program was running setuid
978or setgid, or the \fB\-T\fR switch was used), neither variable is used.
979The program should instead say:
980.Sp
981.Vb 1
982\& use lib "/my/directory";
983.Ve
984.IP "\s-1PERL5OPT\s0" 12
985.IX Item "PERL5OPT"
986Command-line options (switches). Switches in this variable are taken
987as if they were on every Perl command line. Only the \fB\-[DIMUdmtw]\fR
988switches are allowed. When running taint checks (because the program
989was running setuid or setgid, or the \fB\-T\fR switch was used), this
990variable is ignored. If \s-1PERL5OPT\s0 begins with \fB\-T\fR, tainting will be
991enabled, and any subsequent options ignored.
992.IP "\s-1PERLIO\s0" 12
993.IX Item "PERLIO"
994A space (or colon) separated list of PerlIO layers. If perl is built
995to use PerlIO system for \s-1IO\s0 (the default) these layers effect perl's \s-1IO\s0.
996.Sp
997It is conventional to start layer names with a colon e.g. \f(CW\*(C`:perlio\*(C'\fR to
998emphasise their similarity to variable \*(L"attributes\*(R". But the code that parses
999layer specification strings (which is also used to decode the \s-1PERLIO\s0
1000environment variable) treats the colon as a separator.
1001.Sp
1002The list becomes the default for \fIall\fR perl's \s-1IO\s0. Consequently only built-in
1003layers can appear in this list, as external layers (such as :\fIencoding()\fR) need
1004\&\s-1IO\s0 in order to load them!. See \*(L"open pragma\*(R" for how to add external
1005encodings as defaults.
1006.Sp
1007The layers that it makes sense to include in the \s-1PERLIO\s0 environment
1008variable are summarised below. For more details see PerlIO.
1009.RS 12
1010.IP ":bytes" 8
1011.IX Item ":bytes"
1012Turns \fIoff\fR the \f(CW\*(C`:utf8\*(C'\fR flag for the layer below.
1013Unlikely to be useful in global \s-1PERLIO\s0 environment variable.
1014.IP ":crlf" 8
1015.IX Item ":crlf"
1016A layer that implements DOS/Windows like \s-1CRLF\s0 line endings.
1017On read converts pairs of \s-1CR\s0,LF to a single \*(L"\en\*(R" newline character.
1018On write converts each \*(L"\en\*(R" to a \s-1CR\s0,LF pair.
1019Based on the \f(CW\*(C`:perlio\*(C'\fR layer.
1020.IP ":mmap" 8
1021.IX Item ":mmap"
1022A layer which implements \*(L"reading\*(R" of files by using \f(CW\*(C`mmap()\*(C'\fR to
1023make (whole) file appear in the process's address space, and then
1024using that as PerlIO's \*(L"buffer\*(R". This \fImay\fR be faster in certain
1025circumstances for large files, and may result in less physical memory
1026use when multiple processes are reading the same file.
1027.Sp
1028Files which are not \f(CW\*(C`mmap()\*(C'\fR\-able revert to behaving like the \f(CW\*(C`:perlio\*(C'\fR
1029layer. Writes also behave like \f(CW\*(C`:perlio\*(C'\fR layer as \f(CW\*(C`mmap()\*(C'\fR for write
1030needs extra house-keeping (to extend the file) which negates any advantage.
1031.Sp
1032The \f(CW\*(C`:mmap\*(C'\fR layer will not exist if platform does not support \f(CW\*(C`mmap()\*(C'\fR.
1033.IP ":perlio" 8
1034.IX Item ":perlio"
1035A from scratch implementation of buffering for PerlIO. Provides fast
1036access to the buffer for \f(CW\*(C`sv_gets\*(C'\fR which implements perl's readline/<>
1037and in general attempts to minimize data copying.
1038.Sp
1039\&\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.
1040.IP ":raw" 8
1041.IX Item ":raw"
1042Applying the <:raw> layer is equivalent to calling \f(CW\*(C`binmode($fh)\*(C'\fR.
1043It makes the stream pass each byte as-is without any translation.
1044In particular \s-1CRLF\s0 translation, and/or :utf8 inuited from locale
1045are disabled.
1046.Sp
1047Arranges for all accesses go straight to the lowest buffered layer provided
1048by the configration. That is it strips off any layers above that layer.
1049.Sp
1050In Perl 5.6 and some books the \f(CW\*(C`:raw\*(C'\fR layer (previously sometimes also
1051referred to as a \*(L"discipline\*(R") is documented as the inverse of the
1052\&\f(CW\*(C`:crlf\*(C'\fR layer. That is no longer the case \- other layers which would
1053alter binary nature of the stream are also disabled. If you want \s-1UNIX\s0
1054line endings on a platform that normally does \s-1CRLF\s0 translation, but still
1055want \s-1UTF\-8\s0 or encoding defaults the appropriate thing to do is to add
1056\&\f(CW\*(C`:perlio\*(C'\fR to \s-1PERLIO\s0 environment variable.
1057.IP ":stdio" 8
1058.IX Item ":stdio"
1059This layer provides PerlIO interface by wrapping system's \s-1ANSI\s0 C \*(L"stdio\*(R"
1060library calls. The layer provides both buffering and \s-1IO\s0.
1061Note that \f(CW\*(C`:stdio\*(C'\fR layer does \fInot\fR do \s-1CRLF\s0 translation even if that
1062is platforms normal behaviour. You will need a \f(CW\*(C`:crlf\*(C'\fR layer above it
1063to do that.
1064.IP ":unix" 8
1065.IX Item ":unix"
1066Lowest level layer which provides basic PerlIO operations in terms of
1067\&\s-1UNIX/POSIX\s0 numeric file descriptor calls
1068\&\f(CW\*(C`open(), read(), write(), lseek(), close()\*(C'\fR
1069.IP ":utf8" 8
1070.IX Item ":utf8"
1071Turns on a flag on the layer below to tell perl that data sent to the
1072stream should be converted to perl internal \*(L"utf8\*(R" form and that data from the
1073stream should be considered as so encoded. On \s-1ASCII\s0 based platforms the
1074encoding is \s-1UTF\-8\s0 and on \s-1EBCDIC\s0 platforms \s-1UTF\-EBCDIC\s0.
1075May be useful in \s-1PERLIO\s0 environment variable to make \s-1UTF\-8\s0 the
1076default. (To turn off that behaviour use \f(CW\*(C`:bytes\*(C'\fR layer.)
1077.IP ":win32" 8
1078.IX Item ":win32"
1079On Win32 platforms this \fIexperimental\fR layer uses native \*(L"handle\*(R" \s-1IO\s0
1080rather than unix-like numeric file descriptor layer. Known to be
1081buggy in this release.
1082.RE
1083.RS 12
1084.Sp
1085On all platforms the default set of layers should give acceptable results.
1086.Sp
1087For \s-1UNIX\s0 platforms that will equivalent of \*(L"unix perlio\*(R" or \*(L"stdio\*(R".
1088Configure is setup to prefer \*(L"stdio\*(R" implementation if system's library
1089provides for fast access to the buffer, otherwise it uses the \*(L"unix perlio\*(R"
1090implementation.
1091.Sp
1092On Win32 the default in this release is \*(L"unix crlf\*(R". Win32's \*(L"stdio\*(R"
1093has a number of bugs/mis\-features for perl \s-1IO\s0 which are somewhat
1094C compiler vendor/version dependent. Using our own \f(CW\*(C`crlf\*(C'\fR layer as
1095the buffer avoids those issues and makes things more uniform.
1096The \f(CW\*(C`crlf\*(C'\fR layer provides \s-1CRLF\s0 to/from \*(L"\en\*(R" conversion as well as
1097buffering.
1098.Sp
1099This release uses \f(CW\*(C`unix\*(C'\fR as the bottom layer on Win32 and so still uses C
1100compiler's numeric file descriptor routines. There is an experimental native
1101\&\f(CW\*(C`win32\*(C'\fR layer which is expected to be enhanced and should eventually replace
1102the \f(CW\*(C`unix\*(C'\fR layer.
1103.RE
1104.IP "\s-1PERLIO_DEBUG\s0" 12
1105.IX Item "PERLIO_DEBUG"
1106If set to the name of a file or device then certain operations of PerlIO
1107sub-system will be logged to that file (opened as append). Typical uses
1108are \s-1UNIX:\s0
1109.Sp
1110.Vb 1
1111\& PERLIO_DEBUG=/dev/tty perl script ...
1112.Ve
1113.Sp
1114and Win32 approximate equivalent:
1115.Sp
1116.Vb 2
1117\& set PERLIO_DEBUG=CON
1118\& perl script ...
1119.Ve
1120.IP "\s-1PERLLIB\s0" 12
1121.IX Item "PERLLIB"
1122A colon-separated list of directories in which to look for Perl library
1123files before looking in the standard library and the current directory.
1124If \s-1PERL5LIB\s0 is defined, \s-1PERLLIB\s0 is not used.
1125.IP "\s-1PERL5DB\s0" 12
1126.IX Item "PERL5DB"
1127The command used to load the debugger code. The default is:
1128.Sp
1129.Vb 1
1130\& BEGIN { require 'perl5db.pl' }
1131.Ve
1132.IP "\s-1PERL5SHELL\s0 (specific to the Win32 port)" 12
1133.IX Item "PERL5SHELL (specific to the Win32 port)"
1134May be set to an alternative shell that perl must use internally for
1135executing \*(L"backtick\*(R" commands or \fIsystem()\fR. Default is \f(CW\*(C`cmd.exe /x/c\*(C'\fR
1136on WindowsNT and \f(CW\*(C`command.com /c\*(C'\fR on Windows95. The value is considered
1137to be space\-separated. Precede any character that needs to be protected
1138(like a space or backslash) with a backslash.
1139.Sp
1140Note that Perl doesn't use \s-1COMSPEC\s0 for this purpose because
1141\&\s-1COMSPEC\s0 has a high degree of variability among users, leading to
1142portability concerns. Besides, perl can use a shell that may not be
1143fit for interactive use, and setting \s-1COMSPEC\s0 to such a shell may
1144interfere with the proper functioning of other programs (which usually
1145look in \s-1COMSPEC\s0 to find a shell fit for interactive use).
1146.IP "\s-1PERL_DEBUG_MSTATS\s0" 12
1147.IX Item "PERL_DEBUG_MSTATS"
1148Relevant only if perl is compiled with the malloc included with the perl
1149distribution (that is, if \f(CW\*(C`perl \-V:d_mymalloc\*(C'\fR is 'define').
1150If set, this causes memory statistics to be dumped after execution. If set
1151to an integer greater than one, also causes memory statistics to be dumped
1152after compilation.
1153.IP "\s-1PERL_DESTRUCT_LEVEL\s0" 12
1154.IX Item "PERL_DESTRUCT_LEVEL"
1155Relevant only if your perl executable was built with \fB\-DDEBUGGING\fR,
1156this controls the behavior of global destruction of objects and other
1157references. See \*(L"\s-1PERL_DESTRUCT_LEVEL\s0\*(R" in perlhack for more information.
1158.IP "\s-1PERL_ENCODING\s0" 12
1159.IX Item "PERL_ENCODING"
1160If using the \f(CW\*(C`encoding\*(C'\fR pragma without an explicit encoding name, the
1161\&\s-1PERL_ENCODING\s0 environment variable is consulted for an encoding name.
1162.IP "\s-1PERL_ROOT\s0 (specific to the \s-1VMS\s0 port)" 12
1163.IX Item "PERL_ROOT (specific to the VMS port)"
1164A translation concealed rooted logical name that contains perl and the
1165logical device for the \f(CW@INC\fR path on \s-1VMS\s0 only. Other logical names that
1166affect perl on \s-1VMS\s0 include \s-1PERLSHR\s0, \s-1PERL_ENV_TABLES\s0, and
1167\&\s-1SYS$TIMEZONE_DIFFERENTIAL\s0 but are optional and discussed further in
1168perlvms and in \fI\s-1README\s0.vms\fR in the Perl source distribution.
1169.IP "\s-1SYS$LOGIN\s0 (specific to the \s-1VMS\s0 port)" 12
1170.IX Item "SYS$LOGIN (specific to the VMS port)"
1171Used if chdir has no argument and \s-1HOME\s0 and \s-1LOGDIR\s0 are not set.
1172.PP
1173Perl also has environment variables that control how Perl handles data
1174specific to particular natural languages. See perllocale.
1175.PP
1176Apart from these, Perl uses no other environment variables, except
1177to make them available to the program being executed, and to child
1178processes. However, programs running setuid would do well to execute
1179the following lines before doing anything else, just to keep people
1180honest:
1181.PP
1182.Vb 3
1183\& $ENV{PATH} = '/bin:/usr/bin'; # or whatever you need
1184\& $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
1185\& delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
1186.Ve