xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/pod/perlrun.pod (revision 0:68f95e015346)
1*0Sstevel@tonic-gate=head1 NAME
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateperlrun - how to execute the Perl interpreter
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gate=head1 SYNOPSIS
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gateB<perl>	S<[ B<-sTtuUWX> ]>
8*0Sstevel@tonic-gate	S<[ B<-hv> ] [ B<-V>[:I<configvar>] ]>
9*0Sstevel@tonic-gate	S<[ B<-cw> ] [ B<-d>[:I<debugger>] ] [ B<-D>[I<number/list>] ]>
10*0Sstevel@tonic-gate	S<[ B<-pna> ] [ B<-F>I<pattern> ] [ B<-l>[I<octal>] ] [ B<-0>[I<octal/hexadecimal>] ]>
11*0Sstevel@tonic-gate	S<[ B<-I>I<dir> ] [ B<-m>[B<->]I<module> ] [ B<-M>[B<->]I<'module...'> ]>
12*0Sstevel@tonic-gate	S<[ B<-P> ]>
13*0Sstevel@tonic-gate	S<[ B<-S> ]>
14*0Sstevel@tonic-gate	S<[ B<-x>[I<dir>] ]>
15*0Sstevel@tonic-gate	S<[ B<-i>[I<extension>] ]>
16*0Sstevel@tonic-gate	S<[ B<-e> I<'command'> ] [ B<--> ] [ I<programfile> ] [ I<argument> ]...>
17*0Sstevel@tonic-gate	S<[ B<-C [I<number/list>] >]> ]>
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gate=head1 DESCRIPTION
20*0Sstevel@tonic-gate
21*0Sstevel@tonic-gateThe normal way to run a Perl program is by making it directly
22*0Sstevel@tonic-gateexecutable, or else by passing the name of the source file as an
23*0Sstevel@tonic-gateargument on the command line.  (An interactive Perl environment
24*0Sstevel@tonic-gateis also possible--see L<perldebug> for details on how to do that.)
25*0Sstevel@tonic-gateUpon startup, Perl looks for your program in one of the following
26*0Sstevel@tonic-gateplaces:
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate=over 4
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate=item 1.
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gateSpecified line by line via B<-e> switches on the command line.
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate=item 2.
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gateContained in the file specified by the first filename on the command line.
37*0Sstevel@tonic-gate(Note that systems supporting the #! notation invoke interpreters this
38*0Sstevel@tonic-gateway. See L<Location of Perl>.)
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate=item 3.
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gatePassed in implicitly via standard input.  This works only if there are
43*0Sstevel@tonic-gateno filename arguments--to pass arguments to a STDIN-read program you
44*0Sstevel@tonic-gatemust explicitly specify a "-" for the program name.
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate=back
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gateWith methods 2 and 3, Perl starts parsing the input file from the
49*0Sstevel@tonic-gatebeginning, unless you've specified a B<-x> switch, in which case it
50*0Sstevel@tonic-gatescans for the first line starting with #! and containing the word
51*0Sstevel@tonic-gate"perl", and starts there instead.  This is useful for running a program
52*0Sstevel@tonic-gateembedded in a larger message.  (In this case you would indicate the end
53*0Sstevel@tonic-gateof the program using the C<__END__> token.)
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gateThe #! line is always examined for switches as the line is being
56*0Sstevel@tonic-gateparsed.  Thus, if you're on a machine that allows only one argument
57*0Sstevel@tonic-gatewith the #! line, or worse, doesn't even recognize the #! line, you
58*0Sstevel@tonic-gatestill can get consistent switch behavior regardless of how Perl was
59*0Sstevel@tonic-gateinvoked, even if B<-x> was used to find the beginning of the program.
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gateBecause historically some operating systems silently chopped off
62*0Sstevel@tonic-gatekernel interpretation of the #! line after 32 characters, some
63*0Sstevel@tonic-gateswitches may be passed in on the command line, and some may not;
64*0Sstevel@tonic-gateyou could even get a "-" without its letter, if you're not careful.
65*0Sstevel@tonic-gateYou probably want to make sure that all your switches fall either
66*0Sstevel@tonic-gatebefore or after that 32-character boundary.  Most switches don't
67*0Sstevel@tonic-gateactually care if they're processed redundantly, but getting a "-"
68*0Sstevel@tonic-gateinstead of a complete switch could cause Perl to try to execute
69*0Sstevel@tonic-gatestandard input instead of your program.  And a partial B<-I> switch
70*0Sstevel@tonic-gatecould also cause odd results.
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gateSome switches do care if they are processed twice, for instance
73*0Sstevel@tonic-gatecombinations of B<-l> and B<-0>.  Either put all the switches after
74*0Sstevel@tonic-gatethe 32-character boundary (if applicable), or replace the use of
75*0Sstevel@tonic-gateB<-0>I<digits> by C<BEGIN{ $/ = "\0digits"; }>.
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gateParsing of the #! switches starts wherever "perl" is mentioned in the line.
78*0Sstevel@tonic-gateThe sequences "-*" and "- " are specifically ignored so that you could,
79*0Sstevel@tonic-gateif you were so inclined, say
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate    #!/bin/sh -- # -*- perl -*- -p
82*0Sstevel@tonic-gate    eval 'exec perl -wS $0 ${1+"$@"}'
83*0Sstevel@tonic-gate        if $running_under_some_shell;
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gateto let Perl see the B<-p> switch.
86*0Sstevel@tonic-gate
87*0Sstevel@tonic-gateA similar trick involves the B<env> program, if you have it.
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate    #!/usr/bin/env perl
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gateThe examples above use a relative path to the perl interpreter,
92*0Sstevel@tonic-gategetting whatever version is first in the user's path.  If you want
93*0Sstevel@tonic-gatea specific version of Perl, say, perl5.005_57, you should place
94*0Sstevel@tonic-gatethat directly in the #! line's path.
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gateIf the #! line does not contain the word "perl", the program named after
97*0Sstevel@tonic-gatethe #! is executed instead of the Perl interpreter.  This is slightly
98*0Sstevel@tonic-gatebizarre, but it helps people on machines that don't do #!, because they
99*0Sstevel@tonic-gatecan tell a program that their SHELL is F</usr/bin/perl>, and Perl will then
100*0Sstevel@tonic-gatedispatch the program to the correct interpreter for them.
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gateAfter locating your program, Perl compiles the entire program to an
103*0Sstevel@tonic-gateinternal form.  If there are any compilation errors, execution of the
104*0Sstevel@tonic-gateprogram is not attempted.  (This is unlike the typical shell script,
105*0Sstevel@tonic-gatewhich might run part-way through before finding a syntax error.)
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gateIf the program is syntactically correct, it is executed.  If the program
108*0Sstevel@tonic-gateruns off the end without hitting an exit() or die() operator, an implicit
109*0Sstevel@tonic-gateC<exit(0)> is provided to indicate successful completion.
110*0Sstevel@tonic-gate
111*0Sstevel@tonic-gate=head2 #! and quoting on non-Unix systems
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gateUnix's #! technique can be simulated on other systems:
114*0Sstevel@tonic-gate
115*0Sstevel@tonic-gate=over 4
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate=item OS/2
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gatePut
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gate    extproc perl -S -your_switches
122*0Sstevel@tonic-gate
123*0Sstevel@tonic-gateas the first line in C<*.cmd> file (B<-S> due to a bug in cmd.exe's
124*0Sstevel@tonic-gate`extproc' handling).
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate=item MS-DOS
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gateCreate a batch file to run your program, and codify it in
129*0Sstevel@tonic-gateC<ALTERNATE_SHEBANG> (see the F<dosish.h> file in the source
130*0Sstevel@tonic-gatedistribution for more information).
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate=item Win95/NT
133*0Sstevel@tonic-gate
134*0Sstevel@tonic-gateThe Win95/NT installation, when using the ActiveState installer for Perl,
135*0Sstevel@tonic-gatewill modify the Registry to associate the F<.pl> extension with the perl
136*0Sstevel@tonic-gateinterpreter.  If you install Perl by other means (including building from
137*0Sstevel@tonic-gatethe sources), you may have to modify the Registry yourself.  Note that
138*0Sstevel@tonic-gatethis means you can no longer tell the difference between an executable
139*0Sstevel@tonic-gatePerl program and a Perl library file.
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate=item Macintosh
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gateA Macintosh perl program will have the appropriate Creator and
144*0Sstevel@tonic-gateType, so that double-clicking them will invoke the perl application.
145*0Sstevel@tonic-gate
146*0Sstevel@tonic-gate=item VMS
147*0Sstevel@tonic-gate
148*0Sstevel@tonic-gatePut
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate    $ perl -mysw 'f$env("procedure")' 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8' !
151*0Sstevel@tonic-gate    $ exit++ + ++$status != 0 and $exit = $status = undef;
152*0Sstevel@tonic-gate
153*0Sstevel@tonic-gateat the top of your program, where B<-mysw> are any command line switches you
154*0Sstevel@tonic-gatewant to pass to Perl.  You can now invoke the program directly, by saying
155*0Sstevel@tonic-gateC<perl program>, or as a DCL procedure, by saying C<@program> (or implicitly
156*0Sstevel@tonic-gatevia F<DCL$PATH> by just using the name of the program).
157*0Sstevel@tonic-gate
158*0Sstevel@tonic-gateThis incantation is a bit much to remember, but Perl will display it for
159*0Sstevel@tonic-gateyou if you say C<perl "-V:startperl">.
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gate=back
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gateCommand-interpreters on non-Unix systems have rather different ideas
164*0Sstevel@tonic-gateon quoting than Unix shells.  You'll need to learn the special
165*0Sstevel@tonic-gatecharacters in your command-interpreter (C<*>, C<\> and C<"> are
166*0Sstevel@tonic-gatecommon) and how to protect whitespace and these characters to run
167*0Sstevel@tonic-gateone-liners (see B<-e> below).
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gateOn some systems, you may have to change single-quotes to double ones,
170*0Sstevel@tonic-gatewhich you must I<not> do on Unix or Plan 9 systems.  You might also
171*0Sstevel@tonic-gatehave to change a single % to a %%.
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gateFor example:
174*0Sstevel@tonic-gate
175*0Sstevel@tonic-gate    # Unix
176*0Sstevel@tonic-gate    perl -e 'print "Hello world\n"'
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gate    # MS-DOS, etc.
179*0Sstevel@tonic-gate    perl -e "print \"Hello world\n\""
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate    # Macintosh
182*0Sstevel@tonic-gate    print "Hello world\n"
183*0Sstevel@tonic-gate     (then Run "Myscript" or Shift-Command-R)
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate    # VMS
186*0Sstevel@tonic-gate    perl -e "print ""Hello world\n"""
187*0Sstevel@tonic-gate
188*0Sstevel@tonic-gateThe problem is that none of this is reliable: it depends on the
189*0Sstevel@tonic-gatecommand and it is entirely possible neither works.  If B<4DOS> were
190*0Sstevel@tonic-gatethe command shell, this would probably work better:
191*0Sstevel@tonic-gate
192*0Sstevel@tonic-gate    perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""
193*0Sstevel@tonic-gate
194*0Sstevel@tonic-gateB<CMD.EXE> in Windows NT slipped a lot of standard Unix functionality in
195*0Sstevel@tonic-gatewhen nobody was looking, but just try to find documentation for its
196*0Sstevel@tonic-gatequoting rules.
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gateUnder the Macintosh, it depends which environment you are using.  The MacPerl
199*0Sstevel@tonic-gateshell, or MPW, is much like Unix shells in its support for several
200*0Sstevel@tonic-gatequoting variants, except that it makes free use of the Macintosh's non-ASCII
201*0Sstevel@tonic-gatecharacters as control characters.
202*0Sstevel@tonic-gate
203*0Sstevel@tonic-gateThere is no general solution to all of this.  It's just a mess.
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gate=head2 Location of Perl
206*0Sstevel@tonic-gate
207*0Sstevel@tonic-gateIt may seem obvious to say, but Perl is useful only when users can
208*0Sstevel@tonic-gateeasily find it.  When possible, it's good for both F</usr/bin/perl>
209*0Sstevel@tonic-gateand F</usr/local/bin/perl> to be symlinks to the actual binary.  If
210*0Sstevel@tonic-gatethat can't be done, system administrators are strongly encouraged
211*0Sstevel@tonic-gateto put (symlinks to) perl and its accompanying utilities into a
212*0Sstevel@tonic-gatedirectory typically found along a user's PATH, or in some other
213*0Sstevel@tonic-gateobvious and convenient place.
214*0Sstevel@tonic-gate
215*0Sstevel@tonic-gateIn this documentation, C<#!/usr/bin/perl> on the first line of the program
216*0Sstevel@tonic-gatewill stand in for whatever method works on your system.  You are
217*0Sstevel@tonic-gateadvised to use a specific path if you care about a specific version.
218*0Sstevel@tonic-gate
219*0Sstevel@tonic-gate    #!/usr/local/bin/perl5.00554
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gateor if you just want to be running at least version, place a statement
222*0Sstevel@tonic-gatelike this at the top of your program:
223*0Sstevel@tonic-gate
224*0Sstevel@tonic-gate    use 5.005_54;
225*0Sstevel@tonic-gate
226*0Sstevel@tonic-gate=head2 Command Switches
227*0Sstevel@tonic-gate
228*0Sstevel@tonic-gateAs with all standard commands, a single-character switch may be
229*0Sstevel@tonic-gateclustered with the following switch, if any.
230*0Sstevel@tonic-gate
231*0Sstevel@tonic-gate    #!/usr/bin/perl -spi.orig	# same as -s -p -i.orig
232*0Sstevel@tonic-gate
233*0Sstevel@tonic-gateSwitches include:
234*0Sstevel@tonic-gate
235*0Sstevel@tonic-gate=over 5
236*0Sstevel@tonic-gate
237*0Sstevel@tonic-gate=item B<-0>[I<octal/hexadecimal>]
238*0Sstevel@tonic-gate
239*0Sstevel@tonic-gatespecifies the input record separator (C<$/>) as an octal or
240*0Sstevel@tonic-gatehexadecimal number.  If there are no digits, the null character is the
241*0Sstevel@tonic-gateseparator.  Other switches may precede or follow the digits.  For
242*0Sstevel@tonic-gateexample, if you have a version of B<find> which can print filenames
243*0Sstevel@tonic-gateterminated by the null character, you can say this:
244*0Sstevel@tonic-gate
245*0Sstevel@tonic-gate    find . -name '*.orig' -print0 | perl -n0e unlink
246*0Sstevel@tonic-gate
247*0Sstevel@tonic-gateThe special value 00 will cause Perl to slurp files in paragraph mode.
248*0Sstevel@tonic-gateThe value 0777 will cause Perl to slurp files whole because there is no
249*0Sstevel@tonic-gatelegal byte with that value.
250*0Sstevel@tonic-gate
251*0Sstevel@tonic-gateIf you want to specify any Unicode character, use the hexadecimal
252*0Sstevel@tonic-gateformat: C<-0xHHH...>, where the C<H> are valid hexadecimal digits.
253*0Sstevel@tonic-gate(This means that you cannot use the C<-x> with a directory name that
254*0Sstevel@tonic-gateconsists of hexadecimal digits.)
255*0Sstevel@tonic-gate
256*0Sstevel@tonic-gate=item B<-a>
257*0Sstevel@tonic-gate
258*0Sstevel@tonic-gateturns on autosplit mode when used with a B<-n> or B<-p>.  An implicit
259*0Sstevel@tonic-gatesplit command to the @F array is done as the first thing inside the
260*0Sstevel@tonic-gateimplicit while loop produced by the B<-n> or B<-p>.
261*0Sstevel@tonic-gate
262*0Sstevel@tonic-gate    perl -ane 'print pop(@F), "\n";'
263*0Sstevel@tonic-gate
264*0Sstevel@tonic-gateis equivalent to
265*0Sstevel@tonic-gate
266*0Sstevel@tonic-gate    while (<>) {
267*0Sstevel@tonic-gate	@F = split(' ');
268*0Sstevel@tonic-gate	print pop(@F), "\n";
269*0Sstevel@tonic-gate    }
270*0Sstevel@tonic-gate
271*0Sstevel@tonic-gateAn alternate delimiter may be specified using B<-F>.
272*0Sstevel@tonic-gate
273*0Sstevel@tonic-gate=item B<-C [I<number/list>]>
274*0Sstevel@tonic-gate
275*0Sstevel@tonic-gateThe C<-C> flag controls some Unicode of the Perl Unicode features.
276*0Sstevel@tonic-gate
277*0Sstevel@tonic-gateAs of 5.8.1, the C<-C> can be followed either by a number or a list
278*0Sstevel@tonic-gateof option letters.  The letters, their numeric values, and effects
279*0Sstevel@tonic-gateare as follows; listing the letters is equal to summing the numbers.
280*0Sstevel@tonic-gate
281*0Sstevel@tonic-gate    I     1    STDIN is assumed to be in UTF-8
282*0Sstevel@tonic-gate    O     2    STDOUT will be in UTF-8
283*0Sstevel@tonic-gate    E     4    STDERR will be in UTF-8
284*0Sstevel@tonic-gate    S     7    I + O + E
285*0Sstevel@tonic-gate    i     8    UTF-8 is the default PerlIO layer for input streams
286*0Sstevel@tonic-gate    o    16    UTF-8 is the default PerlIO layer for output streams
287*0Sstevel@tonic-gate    D    24    i + o
288*0Sstevel@tonic-gate    A    32    the @ARGV elements are expected to be strings encoded in UTF-8
289*0Sstevel@tonic-gate    L    64    normally the "IOEioA" are unconditional,
290*0Sstevel@tonic-gate               the L makes them conditional on the locale environment
291*0Sstevel@tonic-gate               variables (the LC_ALL, LC_TYPE, and LANG, in the order
292*0Sstevel@tonic-gate               of decreasing precedence) -- if the variables indicate
293*0Sstevel@tonic-gate               UTF-8, then the selected "IOEioA" are in effect
294*0Sstevel@tonic-gate
295*0Sstevel@tonic-gateFor example, C<-COE> and C<-C6> will both turn on UTF-8-ness on both
296*0Sstevel@tonic-gateSTDOUT and STDERR.  Repeating letters is just redundant, not cumulative
297*0Sstevel@tonic-gatenor toggling.
298*0Sstevel@tonic-gate
299*0Sstevel@tonic-gateThe C<io> options mean that any subsequent open() (or similar I/O
300*0Sstevel@tonic-gateoperations) will have the C<:utf8> PerlIO layer implicitly applied
301*0Sstevel@tonic-gateto them, in other words, UTF-8 is expected from any input stream,
302*0Sstevel@tonic-gateand UTF-8 is produced to any output stream.  This is just the default,
303*0Sstevel@tonic-gatewith explicit layers in open() and with binmode() one can manipulate
304*0Sstevel@tonic-gatestreams as usual.
305*0Sstevel@tonic-gate
306*0Sstevel@tonic-gateC<-C> on its own (not followed by any number or option list), or the
307*0Sstevel@tonic-gateempty string C<""> for the C<PERL_UNICODE> environment variable, has the
308*0Sstevel@tonic-gatesame effect as C<-CSDL>.  In other words, the standard I/O handles and
309*0Sstevel@tonic-gatethe default C<open()> layer are UTF-8-fied B<but> only if the locale
310*0Sstevel@tonic-gateenvironment variables indicate a UTF-8 locale.  This behaviour follows
311*0Sstevel@tonic-gatethe I<implicit> (and problematic) UTF-8 behaviour of Perl 5.8.0.
312*0Sstevel@tonic-gate
313*0Sstevel@tonic-gateYou can use C<-C0> (or C<"0"> for C<PERL_UNICODE>) to explicitly
314*0Sstevel@tonic-gatedisable all the above Unicode features.
315*0Sstevel@tonic-gate
316*0Sstevel@tonic-gateThe read-only magic variable C<${^UNICODE}> reflects the numeric value
317*0Sstevel@tonic-gateof this setting.  This is variable is set during Perl startup and is
318*0Sstevel@tonic-gatethereafter read-only.  If you want runtime effects, use the three-arg
319*0Sstevel@tonic-gateopen() (see L<perlfunc/open>), the two-arg binmode() (see L<perlfunc/binmode>),
320*0Sstevel@tonic-gateand the C<open> pragma (see L<open>).
321*0Sstevel@tonic-gate
322*0Sstevel@tonic-gate(In Perls earlier than 5.8.1 the C<-C> switch was a Win32-only switch
323*0Sstevel@tonic-gatethat enabled the use of Unicode-aware "wide system call" Win32 APIs.
324*0Sstevel@tonic-gateThis feature was practically unused, however, and the command line
325*0Sstevel@tonic-gateswitch was therefore "recycled".)
326*0Sstevel@tonic-gate
327*0Sstevel@tonic-gate=item B<-c>
328*0Sstevel@tonic-gate
329*0Sstevel@tonic-gatecauses Perl to check the syntax of the program and then exit without
330*0Sstevel@tonic-gateexecuting it.  Actually, it I<will> execute C<BEGIN>, C<CHECK>, and
331*0Sstevel@tonic-gateC<use> blocks, because these are considered as occurring outside the
332*0Sstevel@tonic-gateexecution of your program.  C<INIT> and C<END> blocks, however, will
333*0Sstevel@tonic-gatebe skipped.
334*0Sstevel@tonic-gate
335*0Sstevel@tonic-gate=item B<-d>
336*0Sstevel@tonic-gate
337*0Sstevel@tonic-gateruns the program under the Perl debugger.  See L<perldebug>.
338*0Sstevel@tonic-gate
339*0Sstevel@tonic-gate=item B<-d:>I<foo[=bar,baz]>
340*0Sstevel@tonic-gate
341*0Sstevel@tonic-gateruns the program under the control of a debugging, profiling, or
342*0Sstevel@tonic-gatetracing module installed as Devel::foo. E.g., B<-d:DProf> executes
343*0Sstevel@tonic-gatethe program using the Devel::DProf profiler.  As with the B<-M>
344*0Sstevel@tonic-gateflag, options may be passed to the Devel::foo package where they
345*0Sstevel@tonic-gatewill be received and interpreted by the Devel::foo::import routine.
346*0Sstevel@tonic-gateThe comma-separated list of options must follow a C<=> character.
347*0Sstevel@tonic-gateSee L<perldebug>.
348*0Sstevel@tonic-gate
349*0Sstevel@tonic-gate=item B<-D>I<letters>
350*0Sstevel@tonic-gate
351*0Sstevel@tonic-gate=item B<-D>I<number>
352*0Sstevel@tonic-gate
353*0Sstevel@tonic-gatesets debugging flags.  To watch how it executes your program, use
354*0Sstevel@tonic-gateB<-Dtls>.  (This works only if debugging is compiled into your
355*0Sstevel@tonic-gatePerl.)  Another nice value is B<-Dx>, which lists your compiled
356*0Sstevel@tonic-gatesyntax tree.  And B<-Dr> displays compiled regular expressions;
357*0Sstevel@tonic-gatethe format of the output is explained in L<perldebguts>.
358*0Sstevel@tonic-gate
359*0Sstevel@tonic-gateAs an alternative, specify a number instead of list of letters (e.g.,
360*0Sstevel@tonic-gateB<-D14> is equivalent to B<-Dtls>):
361*0Sstevel@tonic-gate
362*0Sstevel@tonic-gate        1  p  Tokenizing and parsing
363*0Sstevel@tonic-gate        2  s  Stack snapshots
364*0Sstevel@tonic-gate                with v, displays all stacks
365*0Sstevel@tonic-gate        4  l  Context (loop) stack processing
366*0Sstevel@tonic-gate        8  t  Trace execution
367*0Sstevel@tonic-gate       16  o  Method and overloading resolution
368*0Sstevel@tonic-gate       32  c  String/numeric conversions
369*0Sstevel@tonic-gate       64  P  Print profiling info, preprocessor command for -P, source file input state
370*0Sstevel@tonic-gate      128  m  Memory allocation
371*0Sstevel@tonic-gate      256  f  Format processing
372*0Sstevel@tonic-gate      512  r  Regular expression parsing and execution
373*0Sstevel@tonic-gate     1024  x  Syntax tree dump
374*0Sstevel@tonic-gate     2048  u  Tainting checks
375*0Sstevel@tonic-gate     4096     (Obsolete, previously used for LEAKTEST)
376*0Sstevel@tonic-gate     8192  H  Hash dump -- usurps values()
377*0Sstevel@tonic-gate    16384  X  Scratchpad allocation
378*0Sstevel@tonic-gate    32768  D  Cleaning up
379*0Sstevel@tonic-gate    65536  S  Thread synchronization
380*0Sstevel@tonic-gate   131072  T  Tokenising
381*0Sstevel@tonic-gate   262144  R  Include reference counts of dumped variables (eg when using -Ds)
382*0Sstevel@tonic-gate   524288  J  Do not s,t,P-debug (Jump over) opcodes within package DB
383*0Sstevel@tonic-gate  1048576  v  Verbose: use in conjunction with other flags
384*0Sstevel@tonic-gate  2097152  C  Copy On Write
385*0Sstevel@tonic-gate
386*0Sstevel@tonic-gateAll these flags require B<-DDEBUGGING> when you compile the Perl
387*0Sstevel@tonic-gateexecutable (but see L<Devel::Peek>, L<re> which may change this).
388*0Sstevel@tonic-gateSee the F<INSTALL> file in the Perl source distribution
389*0Sstevel@tonic-gatefor how to do this.  This flag is automatically set if you include B<-g>
390*0Sstevel@tonic-gateoption when C<Configure> asks you about optimizer/debugger flags.
391*0Sstevel@tonic-gate
392*0Sstevel@tonic-gateIf you're just trying to get a print out of each line of Perl code
393*0Sstevel@tonic-gateas it executes, the way that C<sh -x> provides for shell scripts,
394*0Sstevel@tonic-gateyou can't use Perl's B<-D> switch.  Instead do this
395*0Sstevel@tonic-gate
396*0Sstevel@tonic-gate  # If you have "env" utility
397*0Sstevel@tonic-gate  env=PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program
398*0Sstevel@tonic-gate
399*0Sstevel@tonic-gate  # Bourne shell syntax
400*0Sstevel@tonic-gate  $ PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program
401*0Sstevel@tonic-gate
402*0Sstevel@tonic-gate  # csh syntax
403*0Sstevel@tonic-gate  % (setenv PERLDB_OPTS "NonStop=1 AutoTrace=1 frame=2"; perl -dS program)
404*0Sstevel@tonic-gate
405*0Sstevel@tonic-gateSee L<perldebug> for details and variations.
406*0Sstevel@tonic-gate
407*0Sstevel@tonic-gate=item B<-e> I<commandline>
408*0Sstevel@tonic-gate
409*0Sstevel@tonic-gatemay be used to enter one line of program.  If B<-e> is given, Perl
410*0Sstevel@tonic-gatewill not look for a filename in the argument list.  Multiple B<-e>
411*0Sstevel@tonic-gatecommands may be given to build up a multi-line script.  Make sure
412*0Sstevel@tonic-gateto use semicolons where you would in a normal program.
413*0Sstevel@tonic-gate
414*0Sstevel@tonic-gate=item B<-F>I<pattern>
415*0Sstevel@tonic-gate
416*0Sstevel@tonic-gatespecifies the pattern to split on if B<-a> is also in effect.  The
417*0Sstevel@tonic-gatepattern may be surrounded by C<//>, C<"">, or C<''>, otherwise it will be
418*0Sstevel@tonic-gateput in single quotes.
419*0Sstevel@tonic-gate
420*0Sstevel@tonic-gate=item B<-h>
421*0Sstevel@tonic-gate
422*0Sstevel@tonic-gateprints a summary of the options.
423*0Sstevel@tonic-gate
424*0Sstevel@tonic-gate=item B<-i>[I<extension>]
425*0Sstevel@tonic-gate
426*0Sstevel@tonic-gatespecifies that files processed by the C<E<lt>E<gt>> construct are to be
427*0Sstevel@tonic-gateedited in-place.  It does this by renaming the input file, opening the
428*0Sstevel@tonic-gateoutput file by the original name, and selecting that output file as the
429*0Sstevel@tonic-gatedefault for print() statements.  The extension, if supplied, is used to
430*0Sstevel@tonic-gatemodify the name of the old file to make a backup copy, following these
431*0Sstevel@tonic-gaterules:
432*0Sstevel@tonic-gate
433*0Sstevel@tonic-gateIf no extension is supplied, no backup is made and the current file is
434*0Sstevel@tonic-gateoverwritten.
435*0Sstevel@tonic-gate
436*0Sstevel@tonic-gateIf the extension doesn't contain a C<*>, then it is appended to the
437*0Sstevel@tonic-gateend of the current filename as a suffix.  If the extension does
438*0Sstevel@tonic-gatecontain one or more C<*> characters, then each C<*> is replaced
439*0Sstevel@tonic-gatewith the current filename.  In Perl terms, you could think of this
440*0Sstevel@tonic-gateas:
441*0Sstevel@tonic-gate
442*0Sstevel@tonic-gate    ($backup = $extension) =~ s/\*/$file_name/g;
443*0Sstevel@tonic-gate
444*0Sstevel@tonic-gateThis allows you to add a prefix to the backup file, instead of (or in
445*0Sstevel@tonic-gateaddition to) a suffix:
446*0Sstevel@tonic-gate
447*0Sstevel@tonic-gate    $ perl -pi'orig_*' -e 's/bar/baz/' fileA	# backup to 'orig_fileA'
448*0Sstevel@tonic-gate
449*0Sstevel@tonic-gateOr even to place backup copies of the original files into another
450*0Sstevel@tonic-gatedirectory (provided the directory already exists):
451*0Sstevel@tonic-gate
452*0Sstevel@tonic-gate    $ perl -pi'old/*.orig' -e 's/bar/baz/' fileA # backup to 'old/fileA.orig'
453*0Sstevel@tonic-gate
454*0Sstevel@tonic-gateThese sets of one-liners are equivalent:
455*0Sstevel@tonic-gate
456*0Sstevel@tonic-gate    $ perl -pi -e 's/bar/baz/' fileA		# overwrite current file
457*0Sstevel@tonic-gate    $ perl -pi'*' -e 's/bar/baz/' fileA		# overwrite current file
458*0Sstevel@tonic-gate
459*0Sstevel@tonic-gate    $ perl -pi'.orig' -e 's/bar/baz/' fileA	# backup to 'fileA.orig'
460*0Sstevel@tonic-gate    $ perl -pi'*.orig' -e 's/bar/baz/' fileA	# backup to 'fileA.orig'
461*0Sstevel@tonic-gate
462*0Sstevel@tonic-gateFrom the shell, saying
463*0Sstevel@tonic-gate
464*0Sstevel@tonic-gate    $ perl -p -i.orig -e "s/foo/bar/; ... "
465*0Sstevel@tonic-gate
466*0Sstevel@tonic-gateis the same as using the program:
467*0Sstevel@tonic-gate
468*0Sstevel@tonic-gate    #!/usr/bin/perl -pi.orig
469*0Sstevel@tonic-gate    s/foo/bar/;
470*0Sstevel@tonic-gate
471*0Sstevel@tonic-gatewhich is equivalent to
472*0Sstevel@tonic-gate
473*0Sstevel@tonic-gate    #!/usr/bin/perl
474*0Sstevel@tonic-gate    $extension = '.orig';
475*0Sstevel@tonic-gate    LINE: while (<>) {
476*0Sstevel@tonic-gate	if ($ARGV ne $oldargv) {
477*0Sstevel@tonic-gate	    if ($extension !~ /\*/) {
478*0Sstevel@tonic-gate		$backup = $ARGV . $extension;
479*0Sstevel@tonic-gate	    }
480*0Sstevel@tonic-gate	    else {
481*0Sstevel@tonic-gate		($backup = $extension) =~ s/\*/$ARGV/g;
482*0Sstevel@tonic-gate	    }
483*0Sstevel@tonic-gate	    rename($ARGV, $backup);
484*0Sstevel@tonic-gate	    open(ARGVOUT, ">$ARGV");
485*0Sstevel@tonic-gate	    select(ARGVOUT);
486*0Sstevel@tonic-gate	    $oldargv = $ARGV;
487*0Sstevel@tonic-gate	}
488*0Sstevel@tonic-gate	s/foo/bar/;
489*0Sstevel@tonic-gate    }
490*0Sstevel@tonic-gate    continue {
491*0Sstevel@tonic-gate	print;	# this prints to original filename
492*0Sstevel@tonic-gate    }
493*0Sstevel@tonic-gate    select(STDOUT);
494*0Sstevel@tonic-gate
495*0Sstevel@tonic-gateexcept that the B<-i> form doesn't need to compare $ARGV to $oldargv to
496*0Sstevel@tonic-gateknow when the filename has changed.  It does, however, use ARGVOUT for
497*0Sstevel@tonic-gatethe selected filehandle.  Note that STDOUT is restored as the default
498*0Sstevel@tonic-gateoutput filehandle after the loop.
499*0Sstevel@tonic-gate
500*0Sstevel@tonic-gateAs shown above, Perl creates the backup file whether or not any output
501*0Sstevel@tonic-gateis actually changed.  So this is just a fancy way to copy files:
502*0Sstevel@tonic-gate
503*0Sstevel@tonic-gate    $ perl -p -i'/some/file/path/*' -e 1 file1 file2 file3...
504*0Sstevel@tonic-gateor
505*0Sstevel@tonic-gate    $ perl -p -i'.orig' -e 1 file1 file2 file3...
506*0Sstevel@tonic-gate
507*0Sstevel@tonic-gateYou can use C<eof> without parentheses to locate the end of each input
508*0Sstevel@tonic-gatefile, in case you want to append to each file, or reset line numbering
509*0Sstevel@tonic-gate(see example in L<perlfunc/eof>).
510*0Sstevel@tonic-gate
511*0Sstevel@tonic-gateIf, for a given file, Perl is unable to create the backup file as
512*0Sstevel@tonic-gatespecified in the extension then it will skip that file and continue on
513*0Sstevel@tonic-gatewith the next one (if it exists).
514*0Sstevel@tonic-gate
515*0Sstevel@tonic-gateFor a discussion of issues surrounding file permissions and B<-i>,
516*0Sstevel@tonic-gatesee L<perlfaq5/Why does Perl let me delete read-only files?  Why does -i clobber protected files?  Isn't this a bug in Perl?>.
517*0Sstevel@tonic-gate
518*0Sstevel@tonic-gateYou cannot use B<-i> to create directories or to strip extensions from
519*0Sstevel@tonic-gatefiles.
520*0Sstevel@tonic-gate
521*0Sstevel@tonic-gatePerl does not expand C<~> in filenames, which is good, since some
522*0Sstevel@tonic-gatefolks use it for their backup files:
523*0Sstevel@tonic-gate
524*0Sstevel@tonic-gate    $ perl -pi~ -e 's/foo/bar/' file1 file2 file3...
525*0Sstevel@tonic-gate
526*0Sstevel@tonic-gateFinally, the B<-i> switch does not impede execution when no
527*0Sstevel@tonic-gatefiles are given on the command line.  In this case, no backup is made
528*0Sstevel@tonic-gate(the original file cannot, of course, be determined) and processing
529*0Sstevel@tonic-gateproceeds from STDIN to STDOUT as might be expected.
530*0Sstevel@tonic-gate
531*0Sstevel@tonic-gate=item B<-I>I<directory>
532*0Sstevel@tonic-gate
533*0Sstevel@tonic-gateDirectories specified by B<-I> are prepended to the search path for
534*0Sstevel@tonic-gatemodules (C<@INC>), and also tells the C preprocessor where to search for
535*0Sstevel@tonic-gateinclude files.  The C preprocessor is invoked with B<-P>; by default it
536*0Sstevel@tonic-gatesearches /usr/include and /usr/lib/perl.
537*0Sstevel@tonic-gate
538*0Sstevel@tonic-gate=item B<-l>[I<octnum>]
539*0Sstevel@tonic-gate
540*0Sstevel@tonic-gateenables automatic line-ending processing.  It has two separate
541*0Sstevel@tonic-gateeffects.  First, it automatically chomps C<$/> (the input record
542*0Sstevel@tonic-gateseparator) when used with B<-n> or B<-p>.  Second, it assigns C<$\>
543*0Sstevel@tonic-gate(the output record separator) to have the value of I<octnum> so
544*0Sstevel@tonic-gatethat any print statements will have that separator added back on.
545*0Sstevel@tonic-gateIf I<octnum> is omitted, sets C<$\> to the current value of
546*0Sstevel@tonic-gateC<$/>.  For instance, to trim lines to 80 columns:
547*0Sstevel@tonic-gate
548*0Sstevel@tonic-gate    perl -lpe 'substr($_, 80) = ""'
549*0Sstevel@tonic-gate
550*0Sstevel@tonic-gateNote that the assignment C<$\ = $/> is done when the switch is processed,
551*0Sstevel@tonic-gateso the input record separator can be different than the output record
552*0Sstevel@tonic-gateseparator if the B<-l> switch is followed by a B<-0> switch:
553*0Sstevel@tonic-gate
554*0Sstevel@tonic-gate    gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
555*0Sstevel@tonic-gate
556*0Sstevel@tonic-gateThis sets C<$\> to newline and then sets C<$/> to the null character.
557*0Sstevel@tonic-gate
558*0Sstevel@tonic-gate=item B<-m>[B<->]I<module>
559*0Sstevel@tonic-gate
560*0Sstevel@tonic-gate=item B<-M>[B<->]I<module>
561*0Sstevel@tonic-gate
562*0Sstevel@tonic-gate=item B<-M>[B<->]I<'module ...'>
563*0Sstevel@tonic-gate
564*0Sstevel@tonic-gate=item B<-[mM]>[B<->]I<module=arg[,arg]...>
565*0Sstevel@tonic-gate
566*0Sstevel@tonic-gateB<-m>I<module> executes C<use> I<module> C<();> before executing your
567*0Sstevel@tonic-gateprogram.
568*0Sstevel@tonic-gate
569*0Sstevel@tonic-gateB<-M>I<module> executes C<use> I<module> C<;> before executing your
570*0Sstevel@tonic-gateprogram.  You can use quotes to add extra code after the module name,
571*0Sstevel@tonic-gatee.g., C<'-Mmodule qw(foo bar)'>.
572*0Sstevel@tonic-gate
573*0Sstevel@tonic-gateIf the first character after the B<-M> or B<-m> is a dash (C<->)
574*0Sstevel@tonic-gatethen the 'use' is replaced with 'no'.
575*0Sstevel@tonic-gate
576*0Sstevel@tonic-gateA little builtin syntactic sugar means you can also say
577*0Sstevel@tonic-gateB<-mmodule=foo,bar> or B<-Mmodule=foo,bar> as a shortcut for
578*0Sstevel@tonic-gateC<'-Mmodule qw(foo bar)'>.  This avoids the need to use quotes when
579*0Sstevel@tonic-gateimporting symbols.  The actual code generated by B<-Mmodule=foo,bar> is
580*0Sstevel@tonic-gateC<use module split(/,/,q{foo,bar})>.  Note that the C<=> form
581*0Sstevel@tonic-gateremoves the distinction between B<-m> and B<-M>.
582*0Sstevel@tonic-gate
583*0Sstevel@tonic-gate=item B<-n>
584*0Sstevel@tonic-gate
585*0Sstevel@tonic-gatecauses Perl to assume the following loop around your program, which
586*0Sstevel@tonic-gatemakes it iterate over filename arguments somewhat like B<sed -n> or
587*0Sstevel@tonic-gateB<awk>:
588*0Sstevel@tonic-gate
589*0Sstevel@tonic-gate  LINE:
590*0Sstevel@tonic-gate    while (<>) {
591*0Sstevel@tonic-gate	...		# your program goes here
592*0Sstevel@tonic-gate    }
593*0Sstevel@tonic-gate
594*0Sstevel@tonic-gateNote that the lines are not printed by default.  See B<-p> to have
595*0Sstevel@tonic-gatelines printed.  If a file named by an argument cannot be opened for
596*0Sstevel@tonic-gatesome reason, Perl warns you about it and moves on to the next file.
597*0Sstevel@tonic-gate
598*0Sstevel@tonic-gateHere is an efficient way to delete all files that haven't been modifed for
599*0Sstevel@tonic-gateat least a week:
600*0Sstevel@tonic-gate
601*0Sstevel@tonic-gate    find . -mtime +7 -print | perl -nle unlink
602*0Sstevel@tonic-gate
603*0Sstevel@tonic-gateThis is faster than using the B<-exec> switch of B<find> because you don't
604*0Sstevel@tonic-gatehave to start a process on every filename found.  It does suffer from
605*0Sstevel@tonic-gatethe bug of mishandling newlines in pathnames, which you can fix if
606*0Sstevel@tonic-gateyou follow the example under B<-0>.
607*0Sstevel@tonic-gate
608*0Sstevel@tonic-gateC<BEGIN> and C<END> blocks may be used to capture control before or after
609*0Sstevel@tonic-gatethe implicit program loop, just as in B<awk>.
610*0Sstevel@tonic-gate
611*0Sstevel@tonic-gate=item B<-p>
612*0Sstevel@tonic-gate
613*0Sstevel@tonic-gatecauses Perl to assume the following loop around your program, which
614*0Sstevel@tonic-gatemakes it iterate over filename arguments somewhat like B<sed>:
615*0Sstevel@tonic-gate
616*0Sstevel@tonic-gate
617*0Sstevel@tonic-gate  LINE:
618*0Sstevel@tonic-gate    while (<>) {
619*0Sstevel@tonic-gate	...		# your program goes here
620*0Sstevel@tonic-gate    } continue {
621*0Sstevel@tonic-gate	print or die "-p destination: $!\n";
622*0Sstevel@tonic-gate    }
623*0Sstevel@tonic-gate
624*0Sstevel@tonic-gateIf a file named by an argument cannot be opened for some reason, Perl
625*0Sstevel@tonic-gatewarns you about it, and moves on to the next file.  Note that the
626*0Sstevel@tonic-gatelines are printed automatically.  An error occurring during printing is
627*0Sstevel@tonic-gatetreated as fatal.  To suppress printing use the B<-n> switch.  A B<-p>
628*0Sstevel@tonic-gateoverrides a B<-n> switch.
629*0Sstevel@tonic-gate
630*0Sstevel@tonic-gateC<BEGIN> and C<END> blocks may be used to capture control before or after
631*0Sstevel@tonic-gatethe implicit loop, just as in B<awk>.
632*0Sstevel@tonic-gate
633*0Sstevel@tonic-gate=item B<-P>
634*0Sstevel@tonic-gate
635*0Sstevel@tonic-gateB<NOTE: Use of -P is strongly discouraged because of its inherent
636*0Sstevel@tonic-gateproblems, including poor portability.>
637*0Sstevel@tonic-gate
638*0Sstevel@tonic-gateThis option causes your program to be run through the C preprocessor before
639*0Sstevel@tonic-gatecompilation by Perl.  Because both comments and B<cpp> directives begin
640*0Sstevel@tonic-gatewith the # character, you should avoid starting comments with any words
641*0Sstevel@tonic-gaterecognized by the C preprocessor such as C<"if">, C<"else">, or C<"define">.
642*0Sstevel@tonic-gate
643*0Sstevel@tonic-gateIf you're considering using C<-P>, you might also want to look at the
644*0Sstevel@tonic-gateFilter::cpp module from CPAN.
645*0Sstevel@tonic-gate
646*0Sstevel@tonic-gateThe problems of -P include, but are not limited to:
647*0Sstevel@tonic-gate
648*0Sstevel@tonic-gate=over 10
649*0Sstevel@tonic-gate
650*0Sstevel@tonic-gate=item *
651*0Sstevel@tonic-gate
652*0Sstevel@tonic-gateThe C<#!> line is stripped, so any switches there don't apply.
653*0Sstevel@tonic-gate
654*0Sstevel@tonic-gate=item *
655*0Sstevel@tonic-gate
656*0Sstevel@tonic-gateA C<-P> on a C<#!> line doesn't work.
657*0Sstevel@tonic-gate
658*0Sstevel@tonic-gate=item *
659*0Sstevel@tonic-gate
660*0Sstevel@tonic-gateB<All> lines that begin with (whitespace and) a C<#> but
661*0Sstevel@tonic-gatedo not look like cpp commands, are stripped, including anything
662*0Sstevel@tonic-gateinside Perl strings, regular expressions, and here-docs .
663*0Sstevel@tonic-gate
664*0Sstevel@tonic-gate=item *
665*0Sstevel@tonic-gate
666*0Sstevel@tonic-gateIn some platforms the C preprocessor knows too much: it knows about
667*0Sstevel@tonic-gatethe C++ -style until-end-of-line comments starting with C<"//">.
668*0Sstevel@tonic-gateThis will cause problems with common Perl constructs like
669*0Sstevel@tonic-gate
670*0Sstevel@tonic-gate    s/foo//;
671*0Sstevel@tonic-gate
672*0Sstevel@tonic-gatebecause after -P this will became illegal code
673*0Sstevel@tonic-gate
674*0Sstevel@tonic-gate    s/foo
675*0Sstevel@tonic-gate
676*0Sstevel@tonic-gateThe workaround is to use some other quoting separator than C<"/">,
677*0Sstevel@tonic-gatelike for example C<"!">:
678*0Sstevel@tonic-gate
679*0Sstevel@tonic-gate    s!foo!!;
680*0Sstevel@tonic-gate
681*0Sstevel@tonic-gate
682*0Sstevel@tonic-gate
683*0Sstevel@tonic-gate=item *
684*0Sstevel@tonic-gate
685*0Sstevel@tonic-gateIt requires not only a working C preprocessor but also a working
686*0Sstevel@tonic-gateF<sed>.  If not on UNIX, you are probably out of luck on this.
687*0Sstevel@tonic-gate
688*0Sstevel@tonic-gate=item *
689*0Sstevel@tonic-gate
690*0Sstevel@tonic-gateScript line numbers are not preserved.
691*0Sstevel@tonic-gate
692*0Sstevel@tonic-gate=item *
693*0Sstevel@tonic-gate
694*0Sstevel@tonic-gateThe C<-x> does not work with C<-P>.
695*0Sstevel@tonic-gate
696*0Sstevel@tonic-gate=back
697*0Sstevel@tonic-gate
698*0Sstevel@tonic-gate=item B<-s>
699*0Sstevel@tonic-gate
700*0Sstevel@tonic-gateenables rudimentary switch parsing for switches on the command
701*0Sstevel@tonic-gateline after the program name but before any filename arguments (or before
702*0Sstevel@tonic-gatean argument of B<-->).  This means you can have switches with two leading
703*0Sstevel@tonic-gatedashes (B<--help>).  Any switch found there is removed from @ARGV and sets the
704*0Sstevel@tonic-gatecorresponding variable in the Perl program.  The following program
705*0Sstevel@tonic-gateprints "1" if the program is invoked with a B<-xyz> switch, and "abc"
706*0Sstevel@tonic-gateif it is invoked with B<-xyz=abc>.
707*0Sstevel@tonic-gate
708*0Sstevel@tonic-gate    #!/usr/bin/perl -s
709*0Sstevel@tonic-gate    if ($xyz) { print "$xyz\n" }
710*0Sstevel@tonic-gate
711*0Sstevel@tonic-gateDo note that B<--help> creates the variable ${-help}, which is not compliant
712*0Sstevel@tonic-gatewith C<strict refs>.
713*0Sstevel@tonic-gate
714*0Sstevel@tonic-gate=item B<-S>
715*0Sstevel@tonic-gate
716*0Sstevel@tonic-gatemakes Perl use the PATH environment variable to search for the
717*0Sstevel@tonic-gateprogram (unless the name of the program contains directory separators).
718*0Sstevel@tonic-gate
719*0Sstevel@tonic-gateOn some platforms, this also makes Perl append suffixes to the
720*0Sstevel@tonic-gatefilename while searching for it.  For example, on Win32 platforms,
721*0Sstevel@tonic-gatethe ".bat" and ".cmd" suffixes are appended if a lookup for the
722*0Sstevel@tonic-gateoriginal name fails, and if the name does not already end in one
723*0Sstevel@tonic-gateof those suffixes.  If your Perl was compiled with DEBUGGING turned
724*0Sstevel@tonic-gateon, using the -Dp switch to Perl shows how the search progresses.
725*0Sstevel@tonic-gate
726*0Sstevel@tonic-gateTypically this is used to emulate #! startup on platforms that
727*0Sstevel@tonic-gatedon't support #!.  This example works on many platforms that
728*0Sstevel@tonic-gatehave a shell compatible with Bourne shell:
729*0Sstevel@tonic-gate
730*0Sstevel@tonic-gate    #!/usr/bin/perl
731*0Sstevel@tonic-gate    eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
732*0Sstevel@tonic-gate	    if $running_under_some_shell;
733*0Sstevel@tonic-gate
734*0Sstevel@tonic-gateThe system ignores the first line and feeds the program to F</bin/sh>,
735*0Sstevel@tonic-gatewhich proceeds to try to execute the Perl program as a shell script.
736*0Sstevel@tonic-gateThe shell executes the second line as a normal shell command, and thus
737*0Sstevel@tonic-gatestarts up the Perl interpreter.  On some systems $0 doesn't always
738*0Sstevel@tonic-gatecontain the full pathname, so the B<-S> tells Perl to search for the
739*0Sstevel@tonic-gateprogram if necessary.  After Perl locates the program, it parses the
740*0Sstevel@tonic-gatelines and ignores them because the variable $running_under_some_shell
741*0Sstevel@tonic-gateis never true.  If the program will be interpreted by csh, you will need
742*0Sstevel@tonic-gateto replace C<${1+"$@"}> with C<$*>, even though that doesn't understand
743*0Sstevel@tonic-gateembedded spaces (and such) in the argument list.  To start up sh rather
744*0Sstevel@tonic-gatethan csh, some systems may have to replace the #! line with a line
745*0Sstevel@tonic-gatecontaining just a colon, which will be politely ignored by Perl.  Other
746*0Sstevel@tonic-gatesystems can't control that, and need a totally devious construct that
747*0Sstevel@tonic-gatewill work under any of B<csh>, B<sh>, or Perl, such as the following:
748*0Sstevel@tonic-gate
749*0Sstevel@tonic-gate	eval '(exit $?0)' && eval 'exec perl -wS $0 ${1+"$@"}'
750*0Sstevel@tonic-gate	& eval 'exec /usr/bin/perl -wS $0 $argv:q'
751*0Sstevel@tonic-gate		if $running_under_some_shell;
752*0Sstevel@tonic-gate
753*0Sstevel@tonic-gateIf the filename supplied contains directory separators (i.e., is an
754*0Sstevel@tonic-gateabsolute or relative pathname), and if that file is not found,
755*0Sstevel@tonic-gateplatforms that append file extensions will do so and try to look
756*0Sstevel@tonic-gatefor the file with those extensions added, one by one.
757*0Sstevel@tonic-gate
758*0Sstevel@tonic-gateOn DOS-like platforms, if the program does not contain directory
759*0Sstevel@tonic-gateseparators, it will first be searched for in the current directory
760*0Sstevel@tonic-gatebefore being searched for on the PATH.  On Unix platforms, the
761*0Sstevel@tonic-gateprogram will be searched for strictly on the PATH.
762*0Sstevel@tonic-gate
763*0Sstevel@tonic-gate=item B<-t>
764*0Sstevel@tonic-gate
765*0Sstevel@tonic-gateLike B<-T>, but taint checks will issue warnings rather than fatal
766*0Sstevel@tonic-gateerrors.  These warnings can be controlled normally with C<no warnings
767*0Sstevel@tonic-gateqw(taint)>.
768*0Sstevel@tonic-gate
769*0Sstevel@tonic-gateB<NOTE: this is not a substitute for -T.> This is meant only to be
770*0Sstevel@tonic-gateused as a temporary development aid while securing legacy code:
771*0Sstevel@tonic-gatefor real production code and for new secure code written from scratch
772*0Sstevel@tonic-gatealways use the real B<-T>.
773*0Sstevel@tonic-gate
774*0Sstevel@tonic-gate=item B<-T>
775*0Sstevel@tonic-gate
776*0Sstevel@tonic-gateforces "taint" checks to be turned on so you can test them.  Ordinarily
777*0Sstevel@tonic-gatethese checks are done only when running setuid or setgid.  It's a
778*0Sstevel@tonic-gategood idea to turn them on explicitly for programs that run on behalf
779*0Sstevel@tonic-gateof someone else whom you might not necessarily trust, such as CGI
780*0Sstevel@tonic-gateprograms or any internet servers you might write in Perl.  See
781*0Sstevel@tonic-gateL<perlsec> for details.  For security reasons, this option must be
782*0Sstevel@tonic-gateseen by Perl quite early; usually this means it must appear early
783*0Sstevel@tonic-gateon the command line or in the #! line for systems which support
784*0Sstevel@tonic-gatethat construct.
785*0Sstevel@tonic-gate
786*0Sstevel@tonic-gate=item B<-u>
787*0Sstevel@tonic-gate
788*0Sstevel@tonic-gateThis obsolete switch causes Perl to dump core after compiling your
789*0Sstevel@tonic-gateprogram.  You can then in theory take this core dump and turn it
790*0Sstevel@tonic-gateinto an executable file by using the B<undump> program (not supplied).
791*0Sstevel@tonic-gateThis speeds startup at the expense of some disk space (which you
792*0Sstevel@tonic-gatecan minimize by stripping the executable).  (Still, a "hello world"
793*0Sstevel@tonic-gateexecutable comes out to about 200K on my machine.)  If you want to
794*0Sstevel@tonic-gateexecute a portion of your program before dumping, use the dump()
795*0Sstevel@tonic-gateoperator instead.  Note: availability of B<undump> is platform
796*0Sstevel@tonic-gatespecific and may not be available for a specific port of Perl.
797*0Sstevel@tonic-gate
798*0Sstevel@tonic-gateThis switch has been superseded in favor of the new Perl code
799*0Sstevel@tonic-gategenerator backends to the compiler.  See L<B> and L<B::Bytecode>
800*0Sstevel@tonic-gatefor details.
801*0Sstevel@tonic-gate
802*0Sstevel@tonic-gate=item B<-U>
803*0Sstevel@tonic-gate
804*0Sstevel@tonic-gateallows Perl to do unsafe operations.  Currently the only "unsafe"
805*0Sstevel@tonic-gateoperations are the unlinking of directories while running as superuser,
806*0Sstevel@tonic-gateand running setuid programs with fatal taint checks turned into
807*0Sstevel@tonic-gatewarnings.  Note that the B<-w> switch (or the C<$^W> variable) must
808*0Sstevel@tonic-gatebe used along with this option to actually I<generate> the
809*0Sstevel@tonic-gatetaint-check warnings.
810*0Sstevel@tonic-gate
811*0Sstevel@tonic-gate=item B<-v>
812*0Sstevel@tonic-gate
813*0Sstevel@tonic-gateprints the version and patchlevel of your perl executable.
814*0Sstevel@tonic-gate
815*0Sstevel@tonic-gate=item B<-V>
816*0Sstevel@tonic-gate
817*0Sstevel@tonic-gateprints summary of the major perl configuration values and the current
818*0Sstevel@tonic-gatevalues of @INC.
819*0Sstevel@tonic-gate
820*0Sstevel@tonic-gate=item B<-V:>I<name>
821*0Sstevel@tonic-gate
822*0Sstevel@tonic-gatePrints to STDOUT the value of the named configuration variable.
823*0Sstevel@tonic-gateFor example,
824*0Sstevel@tonic-gate
825*0Sstevel@tonic-gate    $ perl -V:man.dir
826*0Sstevel@tonic-gate
827*0Sstevel@tonic-gatewill provide strong clues about what your MANPATH variable should
828*0Sstevel@tonic-gatebe set to in order to access the Perl documentation.
829*0Sstevel@tonic-gate
830*0Sstevel@tonic-gate=item B<-w>
831*0Sstevel@tonic-gate
832*0Sstevel@tonic-gateprints warnings about dubious constructs, such as variable names
833*0Sstevel@tonic-gatethat are mentioned only once and scalar variables that are used
834*0Sstevel@tonic-gatebefore being set, redefined subroutines, references to undefined
835*0Sstevel@tonic-gatefilehandles or filehandles opened read-only that you are attempting
836*0Sstevel@tonic-gateto write on, values used as a number that doesn't look like numbers,
837*0Sstevel@tonic-gateusing an array as though it were a scalar, if your subroutines
838*0Sstevel@tonic-gaterecurse more than 100 deep, and innumerable other things.
839*0Sstevel@tonic-gate
840*0Sstevel@tonic-gateThis switch really just enables the internal C<$^W> variable.  You
841*0Sstevel@tonic-gatecan disable or promote into fatal errors specific warnings using
842*0Sstevel@tonic-gateC<__WARN__> hooks, as described in L<perlvar> and L<perlfunc/warn>.
843*0Sstevel@tonic-gateSee also L<perldiag> and L<perltrap>.  A new, fine-grained warning
844*0Sstevel@tonic-gatefacility is also available if you want to manipulate entire classes
845*0Sstevel@tonic-gateof warnings; see L<warnings> or L<perllexwarn>.
846*0Sstevel@tonic-gate
847*0Sstevel@tonic-gate=item B<-W>
848*0Sstevel@tonic-gate
849*0Sstevel@tonic-gateEnables all warnings regardless of C<no warnings> or C<$^W>.
850*0Sstevel@tonic-gateSee L<perllexwarn>.
851*0Sstevel@tonic-gate
852*0Sstevel@tonic-gate=item B<-X>
853*0Sstevel@tonic-gate
854*0Sstevel@tonic-gateDisables all warnings regardless of C<use warnings> or C<$^W>.
855*0Sstevel@tonic-gateSee L<perllexwarn>.
856*0Sstevel@tonic-gate
857*0Sstevel@tonic-gate=item B<-x> I<directory>
858*0Sstevel@tonic-gate
859*0Sstevel@tonic-gatetells Perl that the program is embedded in a larger chunk of unrelated
860*0Sstevel@tonic-gateASCII text, such as in a mail message.  Leading garbage will be
861*0Sstevel@tonic-gatediscarded until the first line that starts with #! and contains the
862*0Sstevel@tonic-gatestring "perl".  Any meaningful switches on that line will be applied.
863*0Sstevel@tonic-gateIf a directory name is specified, Perl will switch to that directory
864*0Sstevel@tonic-gatebefore running the program.  The B<-x> switch controls only the
865*0Sstevel@tonic-gatedisposal of leading garbage.  The program must be terminated with
866*0Sstevel@tonic-gateC<__END__> if there is trailing garbage to be ignored (the program
867*0Sstevel@tonic-gatecan process any or all of the trailing garbage via the DATA filehandle
868*0Sstevel@tonic-gateif desired).
869*0Sstevel@tonic-gate
870*0Sstevel@tonic-gate=back
871*0Sstevel@tonic-gate
872*0Sstevel@tonic-gate=head1 ENVIRONMENT
873*0Sstevel@tonic-gate
874*0Sstevel@tonic-gate=over 12
875*0Sstevel@tonic-gate
876*0Sstevel@tonic-gate=item HOME
877*0Sstevel@tonic-gate
878*0Sstevel@tonic-gateUsed if chdir has no argument.
879*0Sstevel@tonic-gate
880*0Sstevel@tonic-gate=item LOGDIR
881*0Sstevel@tonic-gate
882*0Sstevel@tonic-gateUsed if chdir has no argument and HOME is not set.
883*0Sstevel@tonic-gate
884*0Sstevel@tonic-gate=item PATH
885*0Sstevel@tonic-gate
886*0Sstevel@tonic-gateUsed in executing subprocesses, and in finding the program if B<-S> is
887*0Sstevel@tonic-gateused.
888*0Sstevel@tonic-gate
889*0Sstevel@tonic-gate=item PERL5LIB
890*0Sstevel@tonic-gate
891*0Sstevel@tonic-gateA list of directories in which to look for Perl library
892*0Sstevel@tonic-gatefiles before looking in the standard library and the current
893*0Sstevel@tonic-gatedirectory.  Any architecture-specific directories under the specified
894*0Sstevel@tonic-gatelocations are automatically included if they exist.  If PERL5LIB is not
895*0Sstevel@tonic-gatedefined, PERLLIB is used.  Directories are separated (like in PATH) by
896*0Sstevel@tonic-gatea colon on unixish platforms and by a semicolon on Windows (the proper
897*0Sstevel@tonic-gatepath separator being given by the command C<perl -V:path_sep>).
898*0Sstevel@tonic-gate
899*0Sstevel@tonic-gateWhen running taint checks (either because the program was running setuid
900*0Sstevel@tonic-gateor setgid, or the B<-T> switch was used), neither variable is used.
901*0Sstevel@tonic-gateThe program should instead say:
902*0Sstevel@tonic-gate
903*0Sstevel@tonic-gate    use lib "/my/directory";
904*0Sstevel@tonic-gate
905*0Sstevel@tonic-gate=item PERL5OPT
906*0Sstevel@tonic-gate
907*0Sstevel@tonic-gateCommand-line options (switches).  Switches in this variable are taken
908*0Sstevel@tonic-gateas if they were on every Perl command line.  Only the B<-[DIMUdmtw]>
909*0Sstevel@tonic-gateswitches are allowed.  When running taint checks (because the program
910*0Sstevel@tonic-gatewas running setuid or setgid, or the B<-T> switch was used), this
911*0Sstevel@tonic-gatevariable is ignored.  If PERL5OPT begins with B<-T>, tainting will be
912*0Sstevel@tonic-gateenabled, and any subsequent options ignored.
913*0Sstevel@tonic-gate
914*0Sstevel@tonic-gate=item PERLIO
915*0Sstevel@tonic-gate
916*0Sstevel@tonic-gateA space (or colon) separated list of PerlIO layers. If perl is built
917*0Sstevel@tonic-gateto use PerlIO system for IO (the default) these layers effect perl's IO.
918*0Sstevel@tonic-gate
919*0Sstevel@tonic-gateIt is conventional to start layer names with a colon e.g. C<:perlio> to
920*0Sstevel@tonic-gateemphasise their similarity to variable "attributes". But the code that parses
921*0Sstevel@tonic-gatelayer specification strings (which is also used to decode the PERLIO
922*0Sstevel@tonic-gateenvironment variable) treats the colon as a separator.
923*0Sstevel@tonic-gate
924*0Sstevel@tonic-gateAn unset or empty PERLIO is equivalent to C<:stdio>.
925*0Sstevel@tonic-gate
926*0Sstevel@tonic-gateThe list becomes the default for I<all> perl's IO. Consequently only built-in
927*0Sstevel@tonic-gatelayers can appear in this list, as external layers (such as :encoding()) need
928*0Sstevel@tonic-gateIO in  order to load them!. See L<"open pragma"|open> for how to add external
929*0Sstevel@tonic-gateencodings as defaults.
930*0Sstevel@tonic-gate
931*0Sstevel@tonic-gateThe layers that it makes sense to include in the PERLIO environment
932*0Sstevel@tonic-gatevariable are briefly summarised below. For more details see L<PerlIO>.
933*0Sstevel@tonic-gate
934*0Sstevel@tonic-gate=over 8
935*0Sstevel@tonic-gate
936*0Sstevel@tonic-gate=item :bytes
937*0Sstevel@tonic-gate
938*0Sstevel@tonic-gateA pseudolayer that turns I<off> the C<:utf8> flag for the layer below.
939*0Sstevel@tonic-gateUnlikely to be useful on its own in the global PERLIO environment variable.
940*0Sstevel@tonic-gateYou perhaps were thinking of C<:crlf:bytes> or C<:perlio:bytes>.
941*0Sstevel@tonic-gate
942*0Sstevel@tonic-gate=item :crlf
943*0Sstevel@tonic-gate
944*0Sstevel@tonic-gateA layer which does CRLF to "\n" translation distinguishing "text" and
945*0Sstevel@tonic-gate"binary" files in the manner of MS-DOS and similar operating systems.
946*0Sstevel@tonic-gate(It currently does I<not> mimic MS-DOS as far as treating of Control-Z
947*0Sstevel@tonic-gateas being an end-of-file marker.)
948*0Sstevel@tonic-gate
949*0Sstevel@tonic-gate=item :mmap
950*0Sstevel@tonic-gate
951*0Sstevel@tonic-gateA layer which implements "reading" of files by using C<mmap()> to
952*0Sstevel@tonic-gatemake (whole) file appear in the process's address space, and then
953*0Sstevel@tonic-gateusing that as PerlIO's "buffer".
954*0Sstevel@tonic-gate
955*0Sstevel@tonic-gate=item :perlio
956*0Sstevel@tonic-gate
957*0Sstevel@tonic-gateThis is a re-implementation of "stdio-like" buffering written as a
958*0Sstevel@tonic-gatePerlIO "layer".  As such it will call whatever layer is below it for
959*0Sstevel@tonic-gateits operations (typically C<:unix>).
960*0Sstevel@tonic-gate
961*0Sstevel@tonic-gate=item :pop
962*0Sstevel@tonic-gate
963*0Sstevel@tonic-gateAn experimental pseudolayer that removes the topmost layer.
964*0Sstevel@tonic-gateUse with the same care as is reserved for nitroglycerin.
965*0Sstevel@tonic-gate
966*0Sstevel@tonic-gate=item :raw
967*0Sstevel@tonic-gate
968*0Sstevel@tonic-gateA pseudolayer that manipulates other layers.  Applying the <:raw>
969*0Sstevel@tonic-gatelayer is equivalent to calling C<binmode($fh)>.  It makes the stream
970*0Sstevel@tonic-gatepass each byte as-is without any translation.  In particular CRLF
971*0Sstevel@tonic-gatetranslation, and/or :utf8 intuited from locale are disabled.
972*0Sstevel@tonic-gate
973*0Sstevel@tonic-gateUnlike in the earlier versions of Perl C<:raw> is I<not>
974*0Sstevel@tonic-gatejust the inverse of C<:crlf> - other layers which would affect the
975*0Sstevel@tonic-gatebinary nature of the stream are also removed or disabled.
976*0Sstevel@tonic-gate
977*0Sstevel@tonic-gate=item :stdio
978*0Sstevel@tonic-gate
979*0Sstevel@tonic-gateThis layer provides PerlIO interface by wrapping system's ANSI C "stdio"
980*0Sstevel@tonic-gatelibrary calls. The layer provides both buffering and IO.
981*0Sstevel@tonic-gateNote that C<:stdio> layer does I<not> do CRLF translation even if that
982*0Sstevel@tonic-gateis platforms normal behaviour. You will need a C<:crlf> layer above it
983*0Sstevel@tonic-gateto do that.
984*0Sstevel@tonic-gate
985*0Sstevel@tonic-gate=item :unix
986*0Sstevel@tonic-gate
987*0Sstevel@tonic-gateLow level layer which calls C<read>, C<write> and C<lseek> etc.
988*0Sstevel@tonic-gate
989*0Sstevel@tonic-gate=item :utf8
990*0Sstevel@tonic-gate
991*0Sstevel@tonic-gateA pseudolayer that turns on a flag on the layer below to tell perl
992*0Sstevel@tonic-gatethat output should be in utf8 and that input should be regarded as
993*0Sstevel@tonic-gatealready in utf8 form.  May be useful in PERLIO environment
994*0Sstevel@tonic-gatevariable to make UTF-8 the default. (To turn off that behaviour
995*0Sstevel@tonic-gateuse C<:bytes> layer.)
996*0Sstevel@tonic-gate
997*0Sstevel@tonic-gate=item :win32
998*0Sstevel@tonic-gate
999*0Sstevel@tonic-gateOn Win32 platforms this I<experimental> layer uses native "handle" IO
1000*0Sstevel@tonic-gaterather than unix-like numeric file descriptor layer. Known to be
1001*0Sstevel@tonic-gatebuggy in this release.
1002*0Sstevel@tonic-gate
1003*0Sstevel@tonic-gate=back
1004*0Sstevel@tonic-gate
1005*0Sstevel@tonic-gateOn all platforms the default set of layers should give acceptable results.
1006*0Sstevel@tonic-gate
1007*0Sstevel@tonic-gateFor UNIX platforms that will equivalent of "unix perlio" or "stdio".
1008*0Sstevel@tonic-gateConfigure is setup to prefer "stdio" implementation if system's library
1009*0Sstevel@tonic-gateprovides for fast access to the buffer, otherwise it uses the "unix perlio"
1010*0Sstevel@tonic-gateimplementation.
1011*0Sstevel@tonic-gate
1012*0Sstevel@tonic-gateOn Win32 the default in this release is "unix crlf". Win32's "stdio"
1013*0Sstevel@tonic-gatehas a number of bugs/mis-features for perl IO which are somewhat
1014*0Sstevel@tonic-gateC compiler vendor/version dependent. Using our own C<crlf> layer as
1015*0Sstevel@tonic-gatethe buffer avoids those issues and makes things more uniform.
1016*0Sstevel@tonic-gateThe C<crlf> layer provides CRLF to/from "\n" conversion as well as
1017*0Sstevel@tonic-gatebuffering.
1018*0Sstevel@tonic-gate
1019*0Sstevel@tonic-gateThis release uses C<unix> as the bottom layer on Win32 and so still uses C
1020*0Sstevel@tonic-gatecompiler's numeric file descriptor routines. There is an experimental native
1021*0Sstevel@tonic-gateC<win32> layer which is expected to be enhanced and should eventually be
1022*0Sstevel@tonic-gatethe default under Win32.
1023*0Sstevel@tonic-gate
1024*0Sstevel@tonic-gate=item PERLIO_DEBUG
1025*0Sstevel@tonic-gate
1026*0Sstevel@tonic-gateIf set to the name of a file or device then certain operations of PerlIO
1027*0Sstevel@tonic-gatesub-system will be logged to that file (opened as append). Typical uses
1028*0Sstevel@tonic-gateare UNIX:
1029*0Sstevel@tonic-gate
1030*0Sstevel@tonic-gate   PERLIO_DEBUG=/dev/tty perl script ...
1031*0Sstevel@tonic-gate
1032*0Sstevel@tonic-gateand Win32 approximate equivalent:
1033*0Sstevel@tonic-gate
1034*0Sstevel@tonic-gate   set PERLIO_DEBUG=CON
1035*0Sstevel@tonic-gate   perl script ...
1036*0Sstevel@tonic-gate
1037*0Sstevel@tonic-gate
1038*0Sstevel@tonic-gate=item PERLLIB
1039*0Sstevel@tonic-gate
1040*0Sstevel@tonic-gateA list of directories in which to look for Perl library
1041*0Sstevel@tonic-gatefiles before looking in the standard library and the current directory.
1042*0Sstevel@tonic-gateIf PERL5LIB is defined, PERLLIB is not used.
1043*0Sstevel@tonic-gate
1044*0Sstevel@tonic-gate=item PERL5DB
1045*0Sstevel@tonic-gate
1046*0Sstevel@tonic-gateThe command used to load the debugger code.  The default is:
1047*0Sstevel@tonic-gate
1048*0Sstevel@tonic-gate	BEGIN { require 'perl5db.pl' }
1049*0Sstevel@tonic-gate
1050*0Sstevel@tonic-gate=item PERL5SHELL (specific to the Win32 port)
1051*0Sstevel@tonic-gate
1052*0Sstevel@tonic-gateMay be set to an alternative shell that perl must use internally for
1053*0Sstevel@tonic-gateexecuting "backtick" commands or system().  Default is C<cmd.exe /x/d/c>
1054*0Sstevel@tonic-gateon WindowsNT and C<command.com /c> on Windows95.  The value is considered
1055*0Sstevel@tonic-gateto be space-separated.  Precede any character that needs to be protected
1056*0Sstevel@tonic-gate(like a space or backslash) with a backslash.
1057*0Sstevel@tonic-gate
1058*0Sstevel@tonic-gateNote that Perl doesn't use COMSPEC for this purpose because
1059*0Sstevel@tonic-gateCOMSPEC has a high degree of variability among users, leading to
1060*0Sstevel@tonic-gateportability concerns.  Besides, perl can use a shell that may not be
1061*0Sstevel@tonic-gatefit for interactive use, and setting COMSPEC to such a shell may
1062*0Sstevel@tonic-gateinterfere with the proper functioning of other programs (which usually
1063*0Sstevel@tonic-gatelook in COMSPEC to find a shell fit for interactive use).
1064*0Sstevel@tonic-gate
1065*0Sstevel@tonic-gate=item PERL_DEBUG_MSTATS
1066*0Sstevel@tonic-gate
1067*0Sstevel@tonic-gateRelevant only if perl is compiled with the malloc included with the perl
1068*0Sstevel@tonic-gatedistribution (that is, if C<perl -V:d_mymalloc> is 'define').
1069*0Sstevel@tonic-gateIf set, this causes memory statistics to be dumped after execution.  If set
1070*0Sstevel@tonic-gateto an integer greater than one, also causes memory statistics to be dumped
1071*0Sstevel@tonic-gateafter compilation.
1072*0Sstevel@tonic-gate
1073*0Sstevel@tonic-gate=item PERL_DESTRUCT_LEVEL
1074*0Sstevel@tonic-gate
1075*0Sstevel@tonic-gateRelevant only if your perl executable was built with B<-DDEBUGGING>,
1076*0Sstevel@tonic-gatethis controls the behavior of global destruction of objects and other
1077*0Sstevel@tonic-gatereferences.  See L<perlhack/PERL_DESTRUCT_LEVEL> for more information.
1078*0Sstevel@tonic-gate
1079*0Sstevel@tonic-gate=item PERL_DL_NONLAZY
1080*0Sstevel@tonic-gate
1081*0Sstevel@tonic-gateSet to one to have perl resolve B<all> undefined symbols when it loads
1082*0Sstevel@tonic-gatea dynamic library.  The default behaviour is to resolve symbols when
1083*0Sstevel@tonic-gatethey are used.  Setting this variable is useful during testing of
1084*0Sstevel@tonic-gateextensions as it ensures that you get an error on misspelled function
1085*0Sstevel@tonic-gatenames even if the test suite doesn't call it.
1086*0Sstevel@tonic-gate
1087*0Sstevel@tonic-gate=item PERL_ENCODING
1088*0Sstevel@tonic-gate
1089*0Sstevel@tonic-gateIf using the C<encoding> pragma without an explicit encoding name, the
1090*0Sstevel@tonic-gatePERL_ENCODING environment variable is consulted for an encoding name.
1091*0Sstevel@tonic-gate
1092*0Sstevel@tonic-gate=item PERL_HASH_SEED
1093*0Sstevel@tonic-gate
1094*0Sstevel@tonic-gate(Since Perl 5.8.1.)  Used to randomise Perl's internal hash function.
1095*0Sstevel@tonic-gateTo emulate the pre-5.8.1 behaviour, set to an integer (zero means
1096*0Sstevel@tonic-gateexactly the same order as 5.8.0).  "Pre-5.8.1" means, among other
1097*0Sstevel@tonic-gatethings, that hash keys will be ordered the same between different runs
1098*0Sstevel@tonic-gateof Perl.
1099*0Sstevel@tonic-gate
1100*0Sstevel@tonic-gateThe default behaviour is to randomise unless the PERL_HASH_SEED is set.
1101*0Sstevel@tonic-gateIf Perl has been compiled with C<-DUSE_HASH_SEED_EXPLICIT>, the default
1102*0Sstevel@tonic-gatebehaviour is B<not> to randomise unless the PERL_HASH_SEED is set.
1103*0Sstevel@tonic-gate
1104*0Sstevel@tonic-gateIf PERL_HASH_SEED is unset or set to a non-numeric string, Perl uses
1105*0Sstevel@tonic-gatethe pseudorandom seed supplied by the operating system and libraries.
1106*0Sstevel@tonic-gateThis means that each different run of Perl will have a different
1107*0Sstevel@tonic-gateordering of the results of keys(), values(), and each().
1108*0Sstevel@tonic-gate
1109*0Sstevel@tonic-gateB<Please note that the hash seed is sensitive information>. Hashes are
1110*0Sstevel@tonic-gaterandomized to protect against local and remote attacks against Perl
1111*0Sstevel@tonic-gatecode. By manually setting a seed this protection may be partially or
1112*0Sstevel@tonic-gatecompletely lost.
1113*0Sstevel@tonic-gate
1114*0Sstevel@tonic-gateSee L<perlsec/"Algorithmic Complexity Attacks"> and
1115*0Sstevel@tonic-gateL</PERL_HASH_SEED_DEBUG> for more information.
1116*0Sstevel@tonic-gate
1117*0Sstevel@tonic-gate=item PERL_HASH_SEED_DEBUG
1118*0Sstevel@tonic-gate
1119*0Sstevel@tonic-gate(Since Perl 5.8.1.)  Set to one to display (to STDERR) the value of
1120*0Sstevel@tonic-gatethe hash seed at the beginning of execution.  This, combined with
1121*0Sstevel@tonic-gateL</PERL_HASH_SEED> is intended to aid in debugging nondeterministic
1122*0Sstevel@tonic-gatebehavior caused by hash randomization.
1123*0Sstevel@tonic-gate
1124*0Sstevel@tonic-gateB<Note that the hash seed is sensitive information>: by knowing it one
1125*0Sstevel@tonic-gatecan craft a denial-of-service attack against Perl code, even remotely,
1126*0Sstevel@tonic-gatesee L<perlsec/"Algorithmic Complexity Attacks"> for more information.
1127*0Sstevel@tonic-gateB<Do not disclose the hash seed> to people who don't need to know it.
1128*0Sstevel@tonic-gateSee also hash_seed() of L<Hash::Util>.
1129*0Sstevel@tonic-gate
1130*0Sstevel@tonic-gate=item PERL_ROOT (specific to the VMS port)
1131*0Sstevel@tonic-gate
1132*0Sstevel@tonic-gateA translation concealed rooted logical name that contains perl and the
1133*0Sstevel@tonic-gatelogical device for the @INC path on VMS only.  Other logical names that
1134*0Sstevel@tonic-gateaffect perl on VMS include PERLSHR, PERL_ENV_TABLES, and
1135*0Sstevel@tonic-gateSYS$TIMEZONE_DIFFERENTIAL but are optional and discussed further in
1136*0Sstevel@tonic-gateL<perlvms> and in F<README.vms> in the Perl source distribution.
1137*0Sstevel@tonic-gate
1138*0Sstevel@tonic-gate=item PERL_SIGNALS
1139*0Sstevel@tonic-gate
1140*0Sstevel@tonic-gateIn Perls 5.8.1 and later.  If set to C<unsafe> the pre-Perl-5.8.0
1141*0Sstevel@tonic-gatesignals behaviour (immediate but unsafe) is restored.  If set to
1142*0Sstevel@tonic-gateC<safe> the safe (or deferred) signals are used.
1143*0Sstevel@tonic-gateSee L<perlipc/"Deferred Signals (Safe signals)">.
1144*0Sstevel@tonic-gate
1145*0Sstevel@tonic-gate=item PERL_UNICODE
1146*0Sstevel@tonic-gate
1147*0Sstevel@tonic-gateEquivalent to the B<-C> command-line switch.  Note that this is not
1148*0Sstevel@tonic-gatea boolean variable-- setting this to C<"1"> is not the right way to
1149*0Sstevel@tonic-gate"enable Unicode" (whatever that would mean).  You can use C<"0"> to
1150*0Sstevel@tonic-gate"disable Unicode", though (or alternatively unset PERL_UNICODE in
1151*0Sstevel@tonic-gateyour shell before starting Perl).  See the description of the C<-C>
1152*0Sstevel@tonic-gateswitch for more information.
1153*0Sstevel@tonic-gate
1154*0Sstevel@tonic-gate=item SYS$LOGIN (specific to the VMS port)
1155*0Sstevel@tonic-gate
1156*0Sstevel@tonic-gateUsed if chdir has no argument and HOME and LOGDIR are not set.
1157*0Sstevel@tonic-gate
1158*0Sstevel@tonic-gate=back
1159*0Sstevel@tonic-gate
1160*0Sstevel@tonic-gatePerl also has environment variables that control how Perl handles data
1161*0Sstevel@tonic-gatespecific to particular natural languages.  See L<perllocale>.
1162*0Sstevel@tonic-gate
1163*0Sstevel@tonic-gateApart from these, Perl uses no other environment variables, except
1164*0Sstevel@tonic-gateto make them available to the program being executed, and to child
1165*0Sstevel@tonic-gateprocesses.  However, programs running setuid would do well to execute
1166*0Sstevel@tonic-gatethe following lines before doing anything else, just to keep people
1167*0Sstevel@tonic-gatehonest:
1168*0Sstevel@tonic-gate
1169*0Sstevel@tonic-gate    $ENV{PATH}  = '/bin:/usr/bin';    # or whatever you need
1170*0Sstevel@tonic-gate    $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
1171*0Sstevel@tonic-gate    delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
1172