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