Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

747 lines
26 KiB

  1. =head1 NAME
  2. perlrun - how to execute the Perl interpreter
  3. =head1 SYNOPSIS
  4. B<perl> S<[ B<-sTuU> ]>
  5. S<[ B<-hv> ] [ B<-V>[:I<configvar>] ]>
  6. S<[ B<-cw> ] [ B<-d>[:I<debugger>] ] [ B<-D>[I<number/list>] ]>
  7. S<[ B<-pna> ] [ B<-F>I<pattern> ] [ B<-l>[I<octal>] ] [ B<-0>[I<octal>] ]>
  8. S<[ B<-I>I<dir> ] [ B<-m>[B<->]I<module> ] [ B<-M>[B<->]I<'module...'> ]>
  9. S<[ B<-P> ]>
  10. S<[ B<-S> ]>
  11. S<[ B<-x>[I<dir>] ]>
  12. S<[ B<-i>[I<extension>] ]>
  13. S<[ B<-e> I<'command'> ] [ B<--> ] [ I<programfile> ] [ I<argument> ]...>
  14. =head1 DESCRIPTION
  15. Upon startup, Perl looks for your script in one of the following
  16. places:
  17. =over 4
  18. =item 1.
  19. Specified line by line via B<-e> switches on the command line.
  20. =item 2.
  21. Contained in the file specified by the first filename on the command line.
  22. (Note that systems supporting the #! notation invoke interpreters this
  23. way. See L<Location of Perl>.)
  24. =item 3.
  25. Passed in implicitly via standard input. This works only if there are
  26. no filename arguments--to pass arguments to a STDIN script you
  27. must explicitly specify a "-" for the script name.
  28. =back
  29. With methods 2 and 3, Perl starts parsing the input file from the
  30. beginning, unless you've specified a B<-x> switch, in which case it
  31. scans for the first line starting with #! and containing the word
  32. "perl", and starts there instead. This is useful for running a script
  33. embedded in a larger message. (In this case you would indicate the end
  34. of the script using the C<__END__> token.)
  35. The #! line is always examined for switches as the line is being
  36. parsed. Thus, if you're on a machine that allows only one argument
  37. with the #! line, or worse, doesn't even recognize the #! line, you
  38. still can get consistent switch behavior regardless of how Perl was
  39. invoked, even if B<-x> was used to find the beginning of the script.
  40. Because many operating systems silently chop off kernel interpretation of
  41. the #! line after 32 characters, some switches may be passed in on the
  42. command line, and some may not; you could even get a "-" without its
  43. letter, if you're not careful. You probably want to make sure that all
  44. your switches fall either before or after that 32 character boundary.
  45. Most switches don't actually care if they're processed redundantly, but
  46. getting a - instead of a complete switch could cause Perl to try to
  47. execute standard input instead of your script. And a partial B<-I> switch
  48. could also cause odd results.
  49. Some switches do care if they are processed twice, for instance combinations
  50. of B<-l> and B<-0>. Either put all the switches after the 32 character
  51. boundary (if applicable), or replace the use of B<-0>I<digits> by
  52. C<BEGIN{ $/ = "\0digits"; }>.
  53. Parsing of the #! switches starts wherever "perl" is mentioned in the line.
  54. The sequences "-*" and "- " are specifically ignored so that you could,
  55. if you were so inclined, say
  56. #!/bin/sh -- # -*- perl -*- -p
  57. eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
  58. if $running_under_some_shell;
  59. to let Perl see the B<-p> switch.
  60. If the #! line does not contain the word "perl", the program named after
  61. the #! is executed instead of the Perl interpreter. This is slightly
  62. bizarre, but it helps people on machines that don't do #!, because they
  63. can tell a program that their SHELL is /usr/bin/perl, and Perl will then
  64. dispatch the program to the correct interpreter for them.
  65. After locating your script, Perl compiles the entire script to an
  66. internal form. If there are any compilation errors, execution of the
  67. script is not attempted. (This is unlike the typical shell script,
  68. which might run part-way through before finding a syntax error.)
  69. If the script is syntactically correct, it is executed. If the script
  70. runs off the end without hitting an exit() or die() operator, an implicit
  71. C<exit(0)> is provided to indicate successful completion.
  72. =head2 #! and quoting on non-Unix systems
  73. Unix's #! technique can be simulated on other systems:
  74. =over 4
  75. =item OS/2
  76. Put
  77. extproc perl -S -your_switches
  78. as the first line in C<*.cmd> file (C<-S> due to a bug in cmd.exe's
  79. `extproc' handling).
  80. =item MS-DOS
  81. Create a batch file to run your script, and codify it in
  82. C<ALTERNATIVE_SHEBANG> (see the F<dosish.h> file in the source
  83. distribution for more information).
  84. =item Win95/NT
  85. The Win95/NT installation, when using the Activeware port of Perl,
  86. will modify the Registry to associate the F<.pl> extension with the perl
  87. interpreter. If you install another port of Perl, including the one
  88. in the Win32 directory of the Perl distribution, then you'll have to
  89. modify the Registry yourself. Note that this means you can no
  90. longer tell the difference between an executable Perl program
  91. and a Perl library file.
  92. =item Macintosh
  93. Macintosh perl scripts will have the appropriate Creator and
  94. Type, so that double-clicking them will invoke the perl application.
  95. =item VMS
  96. Put
  97. $ perl -mysw 'f$env("procedure")' 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8' !
  98. $ exit++ + ++$status != 0 and $exit = $status = undef;
  99. at the top of your script, where C<-mysw> are any command line switches you
  100. want to pass to Perl. You can now invoke the script directly, by saying
  101. C<perl script>, or as a DCL procedure, by saying C<@script> (or implicitly
  102. via F<DCL$PATH> by just using the name of the script).
  103. This incantation is a bit much to remember, but Perl will display it for
  104. you if you say C<perl "-V:startperl">.
  105. =back
  106. Command-interpreters on non-Unix systems have rather different ideas
  107. on quoting than Unix shells. You'll need to learn the special
  108. characters in your command-interpreter (C<*>, C<\> and C<"> are
  109. common) and how to protect whitespace and these characters to run
  110. one-liners (see C<-e> below).
  111. On some systems, you may have to change single-quotes to double ones,
  112. which you must I<NOT> do on Unix or Plan9 systems. You might also
  113. have to change a single % to a %%.
  114. For example:
  115. # Unix
  116. perl -e 'print "Hello world\n"'
  117. # MS-DOS, etc.
  118. perl -e "print \"Hello world\n\""
  119. # Macintosh
  120. print "Hello world\n"
  121. (then Run "Myscript" or Shift-Command-R)
  122. # VMS
  123. perl -e "print ""Hello world\n"""
  124. The problem is that none of this is reliable: it depends on the command
  125. and it is entirely possible neither works. If 4DOS was the command shell, this would
  126. probably work better:
  127. perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""
  128. CMD.EXE in Windows NT slipped a lot of standard Unix functionality in
  129. when nobody was looking, but just try to find documentation for its
  130. quoting rules.
  131. Under the Macintosh, it depends which environment you are using. The MacPerl
  132. shell, or MPW, is much like Unix shells in its support for several
  133. quoting variants, except that it makes free use of the Macintosh's non-ASCII
  134. characters as control characters.
  135. There is no general solution to all of this. It's just a mess.
  136. =head2 Location of Perl
  137. It may seem obvious to say, but Perl is useful only when users can
  138. easily find it. When possible, it's good for both B</usr/bin/perl> and
  139. B</usr/local/bin/perl> to be symlinks to the actual binary. If that
  140. can't be done, system administrators are strongly encouraged to put
  141. (symlinks to) perl and its accompanying utilities, such as perldoc, into
  142. a directory typically found along a user's PATH, or in another obvious
  143. and convenient place.
  144. In this documentation, C<#!/usr/bin/perl> on the first line of the script
  145. will stand in for whatever method works on your system.
  146. =head2 Switches
  147. A single-character switch may be combined with the following switch, if
  148. any.
  149. #!/usr/bin/perl -spi.bak # same as -s -p -i.bak
  150. Switches include:
  151. =over 5
  152. =item B<-0>[I<digits>]
  153. specifies the input record separator (C<$/>) as an octal number. If there are
  154. no digits, the null character is the separator. Other switches may
  155. precede or follow the digits. For example, if you have a version of
  156. B<find> which can print filenames terminated by the null character, you
  157. can say this:
  158. find . -name '*.bak' -print0 | perl -n0e unlink
  159. The special value 00 will cause Perl to slurp files in paragraph mode.
  160. The value 0777 will cause Perl to slurp files whole because there is no
  161. legal character with that value.
  162. =item B<-a>
  163. turns on autosplit mode when used with a B<-n> or B<-p>. An implicit
  164. split command to the @F array is done as the first thing inside the
  165. implicit while loop produced by the B<-n> or B<-p>.
  166. perl -ane 'print pop(@F), "\n";'
  167. is equivalent to
  168. while (<>) {
  169. @F = split(' ');
  170. print pop(@F), "\n";
  171. }
  172. An alternate delimiter may be specified using B<-F>.
  173. =item B<-c>
  174. causes Perl to check the syntax of the script and then exit without
  175. executing it. Actually, it I<will> execute C<BEGIN>, C<END>, and C<use> blocks,
  176. because these are considered as occurring outside the execution of
  177. your program.
  178. =item B<-d>
  179. runs the script under the Perl debugger. See L<perldebug>.
  180. =item B<-d:>I<foo>
  181. runs the script under the control of a debugging or tracing module
  182. installed as Devel::foo. E.g., B<-d:DProf> executes the script using the
  183. Devel::DProf profiler. See L<perldebug>.
  184. =item B<-D>I<letters>
  185. =item B<-D>I<number>
  186. sets debugging flags. To watch how it executes your script, use
  187. B<-Dtls>. (This works only if debugging is compiled into your
  188. Perl.) Another nice value is B<-Dx>, which lists your compiled
  189. syntax tree. And B<-Dr> displays compiled regular expressions. As an
  190. alternative, specify a number instead of list of letters (e.g., B<-D14> is
  191. equivalent to B<-Dtls>):
  192. 1 p Tokenizing and parsing
  193. 2 s Stack snapshots
  194. 4 l Context (loop) stack processing
  195. 8 t Trace execution
  196. 16 o Method and overloading resolution
  197. 32 c String/numeric conversions
  198. 64 P Print preprocessor command for -P
  199. 128 m Memory allocation
  200. 256 f Format processing
  201. 512 r Regular expression parsing and execution
  202. 1024 x Syntax tree dump
  203. 2048 u Tainting checks
  204. 4096 L Memory leaks (needs C<-DLEAKTEST> when compiling Perl)
  205. 8192 H Hash dump -- usurps values()
  206. 16384 X Scratchpad allocation
  207. 32768 D Cleaning up
  208. 65536 S Thread synchronization
  209. All these flags require C<-DDEBUGGING> when you compile the Perl
  210. executable. This flag is automatically set if you include C<-g>
  211. option when C<Configure> asks you about optimizer/debugger flags.
  212. =item B<-e> I<commandline>
  213. may be used to enter one line of script.
  214. If B<-e> is given, Perl
  215. will not look for a script filename in the argument list.
  216. Multiple B<-e> commands may
  217. be given to build up a multi-line script.
  218. Make sure to use semicolons where you would in a normal program.
  219. =item B<-F>I<pattern>
  220. specifies the pattern to split on if B<-a> is also in effect. The
  221. pattern may be surrounded by C<//>, C<"">, or C<''>, otherwise it will be
  222. put in single quotes.
  223. =item B<-h>
  224. prints a summary of the options.
  225. =item B<-i>[I<extension>]
  226. specifies that files processed by the C<E<lt>E<gt>> construct are to be
  227. edited in-place. It does this by renaming the input file, opening the
  228. output file by the original name, and selecting that output file as the
  229. default for print() statements. The extension, if supplied, is used to
  230. modify the name of the old file to make a backup copy, following these
  231. rules:
  232. If no extension is supplied, no backup is made and the current file is
  233. overwritten.
  234. If the extension doesn't contain a C<*> then it is appended to the end
  235. of the current filename as a suffix.
  236. If the extension does contain one or more C<*> characters, then each C<*>
  237. is replaced with the current filename. In perl terms you could think of
  238. this as:
  239. ($backup = $extension) =~ s/\*/$file_name/g;
  240. This allows you to add a prefix to the backup file, instead of (or in
  241. addition to) a suffix:
  242. $ perl -pi'bak_*' -e 's/bar/baz/' fileA # backup to 'bak_fileA'
  243. Or even to place backup copies of the original files into another
  244. directory (provided the directory already exists):
  245. $ perl -pi'old/*.bak' -e 's/bar/baz/' fileA # backup to 'old/fileA.bak'
  246. These sets of one-liners are equivalent:
  247. $ perl -pi -e 's/bar/baz/' fileA # overwrite current file
  248. $ perl -pi'*' -e 's/bar/baz/' fileA # overwrite current file
  249. $ perl -pi'.bak' -e 's/bar/baz/' fileA # backup to 'fileA.bak'
  250. $ perl -pi'*.bak' -e 's/bar/baz/' fileA # backup to 'fileA.bak'
  251. From the shell, saying
  252. $ perl -p -i.bak -e "s/foo/bar/; ... "
  253. is the same as using the script:
  254. #!/usr/bin/perl -pi.bak
  255. s/foo/bar/;
  256. which is equivalent to
  257. #!/usr/bin/perl
  258. $extension = '.bak';
  259. while (<>) {
  260. if ($ARGV ne $oldargv) {
  261. if ($extension !~ /\*/) {
  262. $backup = $ARGV . $extension;
  263. }
  264. else {
  265. ($backup = $extension) =~ s/\*/$ARGV/g;
  266. }
  267. rename($ARGV, $backup);
  268. open(ARGVOUT, ">$ARGV");
  269. select(ARGVOUT);
  270. $oldargv = $ARGV;
  271. }
  272. s/foo/bar/;
  273. }
  274. continue {
  275. print; # this prints to original filename
  276. }
  277. select(STDOUT);
  278. except that the B<-i> form doesn't need to compare $ARGV to $oldargv to
  279. know when the filename has changed. It does, however, use ARGVOUT for
  280. the selected filehandle. Note that STDOUT is restored as the default
  281. output filehandle after the loop.
  282. As shown above, Perl creates the backup file whether or not any output
  283. is actually changed. So this is just a fancy way to copy files:
  284. $ perl -p -i'/some/file/path/*' -e 1 file1 file2 file3...
  285. or
  286. $ perl -p -i'.bak' -e 1 file1 file2 file3...
  287. You can use C<eof> without parentheses to locate the end of each input
  288. file, in case you want to append to each file, or reset line numbering
  289. (see example in L<perlfunc/eof>).
  290. If, for a given file, Perl is unable to create the backup file as
  291. specified in the extension then it will skip that file and continue on
  292. with the next one (if it exists).
  293. For a discussion of issues surrounding file permissions and C<-i>, see
  294. L<perlfaq5/Why does Perl let me delete read-only files? Why does -i clobber protected files? Isn't this a bug in Perl?>.
  295. You cannot use B<-i> to create directories or to strip extensions from
  296. files.
  297. Perl does not expand C<~>, so don't do that.
  298. Finally, note that the B<-i> switch does not impede execution when no
  299. files are given on the command line. In this case, no backup is made
  300. (the original file cannot, of course, be determined) and processing
  301. proceeds from STDIN to STDOUT as might be expected.
  302. =item B<-I>I<directory>
  303. Directories specified by B<-I> are prepended to the search path for
  304. modules (C<@INC>), and also tells the C preprocessor where to search for
  305. include files. The C preprocessor is invoked with B<-P>; by default it
  306. searches /usr/include and /usr/lib/perl.
  307. =item B<-l>[I<octnum>]
  308. enables automatic line-ending processing. It has two effects: first,
  309. it automatically chomps "C<$/>" (the input record separator) when used
  310. with B<-n> or B<-p>, and second, it assigns "C<$\>"
  311. (the output record separator) to have the value of I<octnum> so that
  312. any print statements will have that separator added back on. If
  313. I<octnum> is omitted, sets "C<$\>" to the current value of "C<$/>". For
  314. instance, to trim lines to 80 columns:
  315. perl -lpe 'substr($_, 80) = ""'
  316. Note that the assignment C<$\ = $/> is done when the switch is processed,
  317. so the input record separator can be different than the output record
  318. separator if the B<-l> switch is followed by a B<-0> switch:
  319. gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
  320. This sets C<$\> to newline and then sets C<$/> to the null character.
  321. =item B<-m>[B<->]I<module>
  322. =item B<-M>[B<->]I<module>
  323. =item B<-M>[B<->]I<'module ...'>
  324. =item B<-[mM]>[B<->]I<module=arg[,arg]...>
  325. C<-m>I<module> executes C<use> I<module> C<();> before executing your
  326. script.
  327. C<-M>I<module> executes C<use> I<module> C<;> before executing your
  328. script. You can use quotes to add extra code after the module name,
  329. e.g., C<-M'module qw(foo bar)'>.
  330. If the first character after the C<-M> or C<-m> is a dash (C<->)
  331. then the 'use' is replaced with 'no'.
  332. A little builtin syntactic sugar means you can also say
  333. C<-mmodule=foo,bar> or C<-Mmodule=foo,bar> as a shortcut for
  334. C<-M'module qw(foo bar)'>. This avoids the need to use quotes when
  335. importing symbols. The actual code generated by C<-Mmodule=foo,bar> is
  336. C<use module split(/,/,q{foo,bar})>. Note that the C<=> form
  337. removes the distinction between C<-m> and C<-M>.
  338. =item B<-n>
  339. causes Perl to assume the following loop around your script, which
  340. makes it iterate over filename arguments somewhat like B<sed -n> or
  341. B<awk>:
  342. while (<>) {
  343. ... # your script goes here
  344. }
  345. Note that the lines are not printed by default. See B<-p> to have
  346. lines printed. If a file named by an argument cannot be opened for
  347. some reason, Perl warns you about it, and moves on to the next file.
  348. Here is an efficient way to delete all files older than a week:
  349. find . -mtime +7 -print | perl -nle 'unlink;'
  350. This is faster than using the C<-exec> switch of B<find> because you don't
  351. have to start a process on every filename found.
  352. C<BEGIN> and C<END> blocks may be used to capture control before or after
  353. the implicit loop, just as in B<awk>.
  354. =item B<-p>
  355. causes Perl to assume the following loop around your script, which
  356. makes it iterate over filename arguments somewhat like B<sed>:
  357. while (<>) {
  358. ... # your script goes here
  359. } continue {
  360. print or die "-p destination: $!\n";
  361. }
  362. If a file named by an argument cannot be opened for some reason, Perl
  363. warns you about it, and moves on to the next file. Note that the
  364. lines are printed automatically. An error occurring during printing is
  365. treated as fatal. To suppress printing use the B<-n> switch. A B<-p>
  366. overrides a B<-n> switch.
  367. C<BEGIN> and C<END> blocks may be used to capture control before or after
  368. the implicit loop, just as in awk.
  369. =item B<-P>
  370. causes your script to be run through the C preprocessor before
  371. compilation by Perl. (Because both comments and cpp directives begin
  372. with the # character, you should avoid starting comments with any words
  373. recognized by the C preprocessor such as "if", "else", or "define".)
  374. =item B<-s>
  375. enables some rudimentary switch parsing for switches on the command
  376. line after the script name but before any filename arguments (or before
  377. a B<-->). Any switch found there is removed from @ARGV and sets the
  378. corresponding variable in the Perl script. The following script
  379. prints "true" if and only if the script is invoked with a B<-xyz> switch.
  380. #!/usr/bin/perl -s
  381. if ($xyz) { print "true\n"; }
  382. =item B<-S>
  383. makes Perl use the PATH environment variable to search for the
  384. script (unless the name of the script contains directory separators).
  385. On some platforms, this also makes Perl append suffixes to the
  386. filename while searching for it. For example, on Win32 platforms,
  387. the ".bat" and ".cmd" suffixes are appended if a lookup for the
  388. original name fails, and if the name does not already end in one
  389. of those suffixes. If your Perl was compiled with DEBUGGING turned
  390. on, using the -Dp switch to Perl shows how the search progresses.
  391. If the filename supplied contains directory separators (i.e. it is an
  392. absolute or relative pathname), and if the file is not found,
  393. platforms that append file extensions will do so and try to look
  394. for the file with those extensions added, one by one.
  395. On DOS-like platforms, if the script does not contain directory
  396. separators, it will first be searched for in the current directory
  397. before being searched for on the PATH. On Unix platforms, the
  398. script will be searched for strictly on the PATH.
  399. Typically this is used to emulate #! startup on platforms that
  400. don't support #!. This example works on many platforms that
  401. have a shell compatible with Bourne shell:
  402. #!/usr/bin/perl
  403. eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
  404. if $running_under_some_shell;
  405. The system ignores the first line and feeds the script to /bin/sh,
  406. which proceeds to try to execute the Perl script as a shell script.
  407. The shell executes the second line as a normal shell command, and thus
  408. starts up the Perl interpreter. On some systems $0 doesn't always
  409. contain the full pathname, so the B<-S> tells Perl to search for the
  410. script if necessary. After Perl locates the script, it parses the
  411. lines and ignores them because the variable $running_under_some_shell
  412. is never true. If the script will be interpreted by csh, you will need
  413. to replace C<${1+"$@"}> with C<$*>, even though that doesn't understand
  414. embedded spaces (and such) in the argument list. To start up sh rather
  415. than csh, some systems may have to replace the #! line with a line
  416. containing just a colon, which will be politely ignored by Perl. Other
  417. systems can't control that, and need a totally devious construct that
  418. will work under any of csh, sh, or Perl, such as the following:
  419. eval '(exit $?0)' && eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
  420. & eval 'exec /usr/bin/perl -wS $0 $argv:q'
  421. if $running_under_some_shell;
  422. =item B<-T>
  423. forces "taint" checks to be turned on so you can test them. Ordinarily
  424. these checks are done only when running setuid or setgid. It's a good
  425. idea to turn them on explicitly for programs run on another's behalf,
  426. such as CGI programs. See L<perlsec>. Note that (for security reasons)
  427. this option must be seen by Perl quite early; usually this means it must
  428. appear early on the command line or in the #! line (for systems which
  429. support that).
  430. =item B<-u>
  431. causes Perl to dump core after compiling your script. You can then
  432. in theory take this core dump and turn it into an executable file by using the
  433. B<undump> program (not supplied). This speeds startup at the expense of
  434. some disk space (which you can minimize by stripping the executable).
  435. (Still, a "hello world" executable comes out to about 200K on my
  436. machine.) If you want to execute a portion of your script before dumping,
  437. use the dump() operator instead. Note: availability of B<undump> is
  438. platform specific and may not be available for a specific port of
  439. Perl. It has been superseded by the new perl-to-C compiler, which is more
  440. portable, even though it's still only considered beta.
  441. =item B<-U>
  442. allows Perl to do unsafe operations. Currently the only "unsafe"
  443. operations are the unlinking of directories while running as superuser,
  444. and running setuid programs with fatal taint checks turned into
  445. warnings. Note that the B<-w> switch (or the C<$^W> variable) must
  446. be used along with this option to actually B<generate> the
  447. taint-check warnings.
  448. =item B<-v>
  449. prints the version and patchlevel of your Perl executable.
  450. =item B<-V>
  451. prints summary of the major perl configuration values and the current
  452. value of @INC.
  453. =item B<-V:>I<name>
  454. Prints to STDOUT the value of the named configuration variable.
  455. =item B<-w>
  456. prints warnings about variable names that are mentioned only once, and
  457. scalar variables that are used before being set. Also warns about
  458. redefined subroutines, and references to undefined filehandles or
  459. filehandles opened read-only that you are attempting to write on. Also
  460. warns you if you use values as a number that doesn't look like numbers,
  461. using an array as though it were a scalar, if your subroutines recurse
  462. more than 100 deep, and innumerable other things.
  463. You can disable specific warnings using C<__WARN__> hooks, as described
  464. in L<perlvar> and L<perlfunc/warn>. See also L<perldiag> and L<perltrap>.
  465. =item B<-x> I<directory>
  466. tells Perl that the script is embedded in a message. Leading
  467. garbage will be discarded until the first line that starts with #! and
  468. contains the string "perl". Any meaningful switches on that line will
  469. be applied. If a directory name is specified, Perl will switch to
  470. that directory before running the script. The B<-x> switch controls
  471. only the disposal of leading garbage. The script must be
  472. terminated with C<__END__> if there is trailing garbage to be ignored (the
  473. script can process any or all of the trailing garbage via the DATA
  474. filehandle if desired).
  475. =back
  476. =head1 ENVIRONMENT
  477. =over 12
  478. =item HOME
  479. Used if chdir has no argument.
  480. =item LOGDIR
  481. Used if chdir has no argument and HOME is not set.
  482. =item PATH
  483. Used in executing subprocesses, and in finding the script if B<-S> is
  484. used.
  485. =item PERL5LIB
  486. A colon-separated list of directories in which to look for Perl library
  487. files before looking in the standard library and the current
  488. directory. If PERL5LIB is not defined, PERLLIB is used. When running
  489. taint checks (because the script was running setuid or setgid, or the
  490. B<-T> switch was used), neither variable is used. The script should
  491. instead say
  492. use lib "/my/directory";
  493. =item PERL5OPT
  494. Command-line options (switches). Switches in this variable are taken
  495. as if they were on every Perl command line. Only the B<-[DIMUdmw]>
  496. switches are allowed. When running taint checks (because the script
  497. was running setuid or setgid, or the B<-T> switch was used), this
  498. variable is ignored. If PERL5OPT begins with B<-T>, tainting will be
  499. enabled, and any subsequent options ignored.
  500. =item PERLLIB
  501. A colon-separated list of directories in which to look for Perl library
  502. files before looking in the standard library and the current directory.
  503. If PERL5LIB is defined, PERLLIB is not used.
  504. =item PERL5DB
  505. The command used to load the debugger code. The default is:
  506. BEGIN { require 'perl5db.pl' }
  507. =item PERL5SHELL (specific to WIN32 port)
  508. May be set to an alternative shell that perl must use internally for
  509. executing "backtick" commands or system(). Default is C<cmd.exe /x/c>
  510. on WindowsNT and C<command.com /c> on Windows95. The value is considered
  511. to be space delimited. Precede any character that needs to be protected
  512. (like a space or backslash) with a backslash.
  513. Note that Perl doesn't use COMSPEC for this purpose because
  514. COMSPEC has a high degree of variability among users, leading to
  515. portability concerns. Besides, perl can use a shell that may not be
  516. fit for interactive use, and setting COMSPEC to such a shell may
  517. interfere with the proper functioning of other programs (which usually
  518. look in COMSPEC to find a shell fit for interactive use).
  519. =item PERL_DEBUG_MSTATS
  520. Relevant only if perl is compiled with the malloc included with the perl
  521. distribution (that is, if C<perl -V:d_mymalloc> is 'define').
  522. If set, this causes memory statistics to be dumped after execution. If set
  523. to an integer greater than one, also causes memory statistics to be dumped
  524. after compilation.
  525. =item PERL_DESTRUCT_LEVEL
  526. Relevant only if your perl executable was built with B<-DDEBUGGING>,
  527. this controls the behavior of global destruction of objects and other
  528. references.
  529. =back
  530. Perl also has environment variables that control how Perl handles data
  531. specific to particular natural languages. See L<perllocale>.
  532. Apart from these, Perl uses no other environment variables, except
  533. to make them available to the script being executed, and to child
  534. processes. However, scripts running setuid would do well to execute
  535. the following lines before doing anything else, just to keep people
  536. honest:
  537. $ENV{PATH} = '/bin:/usr/bin'; # or whatever you need
  538. $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
  539. delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};