1=head1 NAME 2 3perlrun - how to execute the Perl interpreter 4 5=head1 SYNOPSIS 6 7B<perl> S<[ B<-gsTtuUWX> ]> 8 S<[ B<-h?v> ] [ B<-V>[:I<configvar>] ]> 9 S<[ B<-cw> ] [ B<-d>[B<t>][:I<debugger>] ] [ B<-D>[I<number/list>] ]> 10 S<[ B<-pna> ] [ B<-F>I<pattern> ] [ B<-l>[I<octal>] ] [ B<-0>[I<octal/hexadecimal>] ]> 11 S<[ B<-I>I<dir> ] [ B<-m>[B<->]I<module> ] [ B<-M>[B<->]I<'module...'> ] [ B<-f> ]> 12 S<[ B<-C [I<number/list>] >]> 13 S<[ B<-S> ]> 14 S<[ B<-x>[I<dir>] ]> 15 S<[ B<-i>[I<extension>] ]> 16 S<[ [B<-e>|B<-E>] I<'command'> ] [ B<--> ] [ I<programfile> ] [ I<argument> ]...> 17 18=head1 DESCRIPTION 19 20The normal way to run a Perl program is by making it directly 21executable, or else by passing the name of the source file as an 22argument on the command line. (An interactive Perl environment 23is also possible--see L<perldebug> for details on how to do that.) 24Upon startup, Perl looks for your program in one of the following 25places: 26 27=over 4 28 29=item 1. 30 31Specified line by line via L<-e|/-e commandline> or L<-E|/-E commandline> 32switches on the command line. 33 34=item 2. 35 36Contained in the file specified by the first filename on the command line. 37(Note that systems supporting the C<#!> notation invoke interpreters this 38way. See L</Location of Perl>.) 39 40=item 3. 41 42Passed in implicitly via standard input. This works only if there are 43no filename arguments--to pass arguments to a STDIN-read program you 44must explicitly specify a "-" for the program name. 45 46=back 47 48With methods 2 and 3, Perl starts parsing the input file from the 49beginning, unless you've specified a L</-x> switch, in which case it 50scans for the first line starting with C<#!> and containing the word 51"perl", and starts there instead. This is useful for running a program 52embedded in a larger message. (In this case you would indicate the end 53of the program using the C<__END__> token.) 54 55The C<#!> line is always examined for switches as the line is being 56parsed. Thus, if you're on a machine that allows only one argument 57with the C<#!> line, or worse, doesn't even recognize the C<#!> line, you 58still can get consistent switch behaviour regardless of how Perl was 59invoked, even if L</-x> was used to find the beginning of the program. 60 61Because historically some operating systems silently chopped off 62kernel interpretation of the C<#!> line after 32 characters, some 63switches may be passed in on the command line, and some may not; 64you could even get a "-" without its letter, if you're not careful. 65You probably want to make sure that all your switches fall either 66before or after that 32-character boundary. Most switches don't 67actually care if they're processed redundantly, but getting a "-" 68instead of a complete switch could cause Perl to try to execute 69standard input instead of your program. And a partial L<-I|/-Idirectory> 70switch could also cause odd results. 71 72Some switches do care if they are processed twice, for instance 73combinations of L<-l|/-l[octnum]> and L<-0|/-0[octalE<sol>hexadecimal]>. 74Either put all the switches after the 32-character boundary (if 75applicable), or replace the use of B<-0>I<digits> by 76C<BEGIN{ $/ = "\0digits"; }>. 77 78Parsing of the C<#!> switches starts wherever "perl" is mentioned in the line. 79The sequences "-*" and "- " are specifically ignored so that you could, 80if you were so inclined, say 81 82 #!/bin/sh 83 #! -*- perl -*- -p 84 eval 'exec perl -x -wS $0 ${1+"$@"}' 85 if 0; 86 87to let Perl see the L</-p> switch. 88 89A similar trick involves the I<env> program, if you have it. 90 91 #!/usr/bin/env perl 92 93The examples above use a relative path to the perl interpreter, 94getting whatever version is first in the user's path. If you want 95a specific version of Perl, say, perl5.14.1, you should place 96that directly in the C<#!> line's path. 97 98If the C<#!> line does not contain the word "perl" nor the word "indir", 99the program named after the C<#!> is executed instead of the Perl 100interpreter. This is slightly bizarre, but it helps people on machines 101that don't do C<#!>, because they can tell a program that their SHELL is 102F</usr/bin/perl>, and Perl will then dispatch the program to the correct 103interpreter for them. 104 105After locating your program, Perl compiles the entire program to an 106internal form. If there are any compilation errors, execution of the 107program is not attempted. (This is unlike the typical shell script, 108which might run part-way through before finding a syntax error.) 109 110If the program is syntactically correct, it is executed. If the program 111runs off the end without hitting an exit() or die() operator, an implicit 112C<exit(0)> is provided to indicate successful completion. 113 114=head2 #! and quoting on non-Unix systems 115X<hashbang> X<#!> 116 117Unix's C<#!> technique can be simulated on other systems: 118 119=over 4 120 121=item OS/2 122 123Put 124 125 extproc perl -S -your_switches 126 127as the first line in C<*.cmd> file (L</-S> due to a bug in cmd.exe's 128`extproc' handling). 129 130=item MS-DOS 131 132Create a batch file to run your program, and codify it in 133C<ALTERNATE_SHEBANG> (see the F<dosish.h> file in the source 134distribution for more information). 135 136=item Win95/NT 137 138The Win95/NT installation, when using the ActiveState installer for Perl, 139will modify the Registry to associate the F<.pl> extension with the perl 140interpreter. If you install Perl by other means (including building from 141the sources), you may have to modify the Registry yourself. Note that 142this means you can no longer tell the difference between an executable 143Perl program and a Perl library file. 144 145=item VMS 146 147Put 148 149 $ perl -mysw 'f$env("procedure")' 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8' ! 150 $ exit++ + ++$status != 0 and $exit = $status = undef; 151 152at the top of your program, where B<-mysw> are any command line switches you 153want to pass to Perl. You can now invoke the program directly, by saying 154C<perl program>, or as a DCL procedure, by saying C<@program> (or implicitly 155via F<DCL$PATH> by just using the name of the program). 156 157This incantation is a bit much to remember, but Perl will display it for 158you if you say C<perl "-V:startperl">. 159 160=back 161 162Command-interpreters on non-Unix systems have rather different ideas 163on quoting than Unix shells. You'll need to learn the special 164characters in your command-interpreter (C<*>, C<\> and C<"> are 165common) and how to protect whitespace and these characters to run 166one-liners (see L<-e|/-e commandline> below). 167 168On some systems, you may have to change single-quotes to double ones, 169which you must I<not> do on Unix or Plan 9 systems. You might also 170have to change a single % to a %%. 171 172For example: 173 174 # Unix 175 perl -e 'print "Hello world\n"' 176 177 # MS-DOS, etc. 178 perl -e "print \"Hello world\n\"" 179 180 # VMS 181 perl -e "print ""Hello world\n""" 182 183The problem is that none of this is reliable: it depends on the 184command and it is entirely possible neither works. If I<4DOS> were 185the command shell, this would probably work better: 186 187 perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>"" 188 189B<CMD.EXE> in Windows NT slipped a lot of standard Unix functionality in 190when nobody was looking, but just try to find documentation for its 191quoting rules. 192 193There is no general solution to all of this. It's just a mess. 194 195=head2 Location of Perl 196X<perl, location of interpreter> 197 198It may seem obvious to say, but Perl is useful only when users can 199easily find it. When possible, it's good for both F</usr/bin/perl> 200and F</usr/local/bin/perl> to be symlinks to the actual binary. If 201that can't be done, system administrators are strongly encouraged 202to put (symlinks to) perl and its accompanying utilities into a 203directory typically found along a user's PATH, or in some other 204obvious and convenient place. 205 206In this documentation, C<#!/usr/bin/perl> on the first line of the program 207will stand in for whatever method works on your system. You are 208advised to use a specific path if you care about a specific version. 209 210 #!/usr/local/bin/perl5.14 211 212or if you just want to be running at least version, place a statement 213like this at the top of your program: 214 215 use v5.14; 216 217=head2 Command Switches 218X<perl, command switches> X<command switches> 219 220As with all standard commands, a single-character switch may be 221clustered with the following switch, if any. 222 223 #!/usr/bin/perl -spi.orig # same as -s -p -i.orig 224 225A C<--> signals the end of options and disables further option processing. Any 226arguments after the C<--> are treated as filenames and arguments. 227 228Switches include: 229 230=over 5 231 232=item B<-0>[I<octal/hexadecimal>] 233X<-0> X<$/> 234 235specifies the input record separator (C<$/>) as an octal or 236hexadecimal number. If there are no digits, the null character is the 237separator. Other switches may precede or follow the digits. For 238example, if you have a version of I<find> which can print filenames 239terminated by the null character, you can say this: 240 241 find . -name '*.orig' -print0 | perl -n0e unlink 242 243The special value 00 will cause Perl to slurp files in paragraph mode. 244 245Any value 0400 or above will cause Perl to slurp files whole, but by convention 246the value 0777 is the one normally used for this purpose. The L</-g> flag 247is a simpler alias for it. 248 249You can also specify the separator character using hexadecimal notation: 250B<-0xI<HHH...>>, where the C<I<H>> are valid hexadecimal digits. Unlike 251the octal form, this one may be used to specify any Unicode character, even 252those beyond 0xFF. So if you I<really> want a record separator of 0777, 253specify it as B<-0x1FF>. (This means that you cannot use the L</-x> option 254with a directory name that consists of hexadecimal digits, or else Perl 255will think you have specified a hex number to B<-0>.) 256 257=item B<-a> 258X<-a> X<autosplit> 259 260turns on autosplit mode when used with a L</-n> or L</-p>. An implicit 261split command to the @F array is done as the first thing inside the 262implicit while loop produced by the L</-n> or L</-p>. 263 264 perl -ane 'print pop(@F), "\n";' 265 266is equivalent to 267 268 while (<>) { 269 @F = split(' '); 270 print pop(@F), "\n"; 271 } 272 273An alternate delimiter may be specified using L<-F|/-Fpattern>. 274 275B<-a> implicitly sets L</-n>. 276 277=item B<-C [I<number/list>]> 278X<-C> 279 280The B<-C> flag controls some of the Perl Unicode features. 281 282As of 5.8.1, the B<-C> can be followed either by a number or a list 283of option letters. The letters, their numeric values, and effects 284are as follows; listing the letters is equal to summing the numbers. 285 286 I 1 STDIN is assumed to be in UTF-8 287 O 2 STDOUT will be in UTF-8 288 E 4 STDERR will be in UTF-8 289 S 7 I + O + E 290 i 8 UTF-8 is the default PerlIO layer for input streams 291 o 16 UTF-8 is the default PerlIO layer for output streams 292 D 24 i + o 293 A 32 the @ARGV elements are expected to be strings encoded 294 in UTF-8 295 L 64 normally the "IOEioA" are unconditional, the L makes 296 them conditional on the locale environment variables 297 (the LC_ALL, LC_CTYPE, and LANG, in the order of 298 decreasing precedence) -- if the variables indicate 299 UTF-8, then the selected "IOEioA" are in effect 300 a 256 Set ${^UTF8CACHE} to -1, to run the UTF-8 caching 301 code in debugging mode. 302 303=for documenting_the_underdocumented 304perl.h gives W/128 as PERL_UNICODE_WIDESYSCALLS "/* for Sarathy */" 305 306=for todo 307perltodo mentions Unicode in %ENV and filenames. I guess that these will be 308options e and f (or F). 309 310For example, B<-COE> and B<-C6> will both turn on UTF-8-ness on both 311STDOUT and STDERR. Repeating letters is just redundant, not cumulative 312nor toggling. 313 314The C<io> options mean that any subsequent open() (or similar I/O 315operations) in main program scope will have the C<:utf8> PerlIO layer 316implicitly applied to them, in other words, UTF-8 is expected from any 317input stream, and UTF-8 is produced to any output stream. This is just 318the default set via L<C<${^OPEN}>|perlvar/${^OPEN}>, 319with explicit layers in open() and with binmode() one can 320manipulate streams as usual. This has no effect on code run in modules. 321 322B<-C> on its own (not followed by any number or option list), or the 323empty string C<""> for the L</PERL_UNICODE> environment variable, has the 324same effect as B<-CSDL>. In other words, the standard I/O handles and 325the default C<open()> layer are UTF-8-fied I<but> only if the locale 326environment variables indicate a UTF-8 locale. This behaviour follows 327the I<implicit> (and problematic) UTF-8 behaviour of Perl 5.8.0. 328(See L<perl581delta/UTF-8 no longer default under UTF-8 locales>.) 329 330You can use B<-C0> (or C<"0"> for C<PERL_UNICODE>) to explicitly 331disable all the above Unicode features. 332 333The read-only magic variable C<${^UNICODE}> reflects the numeric value 334of this setting. This variable is set during Perl startup and is 335thereafter read-only. If you want runtime effects, use the three-arg 336open() (see L<perlfunc/open>), the two-arg binmode() (see L<perlfunc/binmode>), 337and the C<open> pragma (see L<open>). 338 339(In Perls earlier than 5.8.1 the B<-C> switch was a Win32-only switch 340that enabled the use of Unicode-aware "wide system call" Win32 APIs. 341This feature was practically unused, however, and the command line 342switch was therefore "recycled".) 343 344B<Note:> Since perl 5.10.1, if the B<-C> option is used on the C<#!> line, 345it must be specified on the command line as well, since the standard streams 346are already set up at this point in the execution of the perl interpreter. 347You can also use binmode() to set the encoding of an I/O stream. 348 349=item B<-c> 350X<-c> 351 352causes Perl to check the syntax of the program and then exit without 353executing it. Actually, it I<will> execute any C<BEGIN>, C<UNITCHECK>, 354or C<CHECK> blocks and any C<use> statements: these are considered as 355occurring outside the execution of your program. C<INIT> and C<END> 356blocks, however, will be skipped. 357 358=item B<-d> 359X<-d> X<-dt> 360 361=item B<-dt> 362 363runs the program under the Perl debugger. See L<perldebug>. 364If B<t> is specified, it indicates to the debugger that threads 365will be used in the code being debugged. 366 367=item B<-d:>I<MOD[=bar,baz]> 368X<-d> X<-dt> 369 370=item B<-dt:>I<MOD[=bar,baz]> 371 372runs the program under the control of a debugging, profiling, or tracing 373module installed as C<Devel::I<MOD>>. E.g., B<-d:DProf> executes the 374program using the C<Devel::DProf> profiler. As with the L<-M|/-M[-]module> 375flag, options may be passed to the C<Devel::I<MOD>> package where they will 376be received and interpreted by the C<Devel::I<MOD>::import> routine. Again, 377like B<-M>, use -B<-d:-I<MOD>> to call C<Devel::I<MOD>::unimport> instead of 378import. The comma-separated list of options must follow a C<=> character. 379If B<t> is specified, it indicates to the debugger that threads will be used 380in the code being debugged. See L<perldebug>. 381 382=item B<-D>I<letters> 383X<-D> X<DEBUGGING> X<-DDEBUGGING> 384 385=item B<-D>I<number> 386 387sets debugging flags. This switch is enabled only if your perl binary has 388been built with debugging enabled: normal production perls won't have 389been. 390 391For example, to watch how perl executes your program, use B<-Dtls>. 392Another nice value is B<-Dx>, which lists your compiled syntax tree, and 393B<-Dr> displays compiled regular expressions; the format of the output is 394explained in L<perldebguts>. 395 396As an alternative, specify a number instead of list of letters (e.g., 397B<-D14> is equivalent to B<-Dtls>): 398 399 1 p Tokenizing and parsing (with v, displays parse 400 stack) 401 2 s Stack snapshots (with v, displays all stacks) 402 4 l Context (loop) stack processing 403 8 t Trace execution 404 16 o Method and overloading resolution 405 32 c String/numeric conversions 406 64 P Print profiling info, source file input state 407 128 m Memory and SV allocation 408 256 f Format processing 409 512 r Regular expression parsing and execution 410 1024 x Syntax tree dump 411 2048 u Tainting checks 412 4096 U Unofficial, User hacking (reserved for private, 413 unreleased use) 414 8192 h Show hash randomization debug output (changes to 415 PL_hash_rand_bits and their origin) 416 16384 X Scratchpad allocation 417 32768 D Cleaning up 418 65536 S Op slab allocation 419 131072 T Tokenizing 420 262144 R Include reference counts of dumped variables 421 (eg when using -Ds) 422 524288 J show s,t,P-debug (don't Jump over) on opcodes within 423 package DB 424 1048576 v Verbose: use in conjunction with other flags to 425 increase the verbosity of the output. Is a no-op on 426 many of the other flags 427 2097152 C Copy On Write 428 4194304 A Consistency checks on internal structures 429 8388608 q quiet - currently only suppresses the "EXECUTING" 430 message 431 16777216 M trace smart match resolution 432 33554432 B dump suBroutine definitions, including special 433 Blocks like BEGIN 434 67108864 L trace Locale-related info; what gets output is very 435 subject to change 436 134217728 i trace PerlIO layer processing. Set PERLIO_DEBUG to 437 the filename to trace to. 438 268435456 y trace y///, tr/// compilation and execution 439 440All these flags require B<-DDEBUGGING> when you compile the Perl 441executable (but see C<:opd> in L<Devel::Peek> or L<re/'debug' mode> 442which may change this). 443See the F<INSTALL> file in the Perl source distribution 444for how to do this. 445 446If you're just trying to get a print out of each line of Perl code 447as it executes, the way that C<sh -x> provides for shell scripts, 448you can't use Perl's B<-D> switch. Instead do this 449 450 # If you have "env" utility 451 env PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program 452 453 # Bourne shell syntax 454 $ PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program 455 456 # csh syntax 457 % (setenv PERLDB_OPTS "NonStop=1 AutoTrace=1 frame=2"; perl -dS program) 458 459See L<perldebug> for details and variations. 460 461=item B<-e> I<commandline> 462X<-e> 463 464may be used to enter one line of program. If B<-e> is given, Perl 465will not look for a filename in the argument list. Multiple B<-e> 466commands may be given to build up a multi-line script. Make sure 467to use semicolons where you would in a normal program. 468 469=item B<-E> I<commandline> 470X<-E> 471 472behaves just like L<-e|/-e commandline>, except that it implicitly 473enables all optional features (in the main compilation unit). See 474L<feature>. 475 476=item B<-f> 477X<-f> X<sitecustomize> X<sitecustomize.pl> 478 479Disable executing F<$Config{sitelib}/sitecustomize.pl> at startup. 480 481Perl can be built so that it by default will try to execute 482F<$Config{sitelib}/sitecustomize.pl> at startup (in a BEGIN block). 483This is a hook that allows the sysadmin to customize how Perl behaves. 484It can for instance be used to add entries to the @INC array to make Perl 485find modules in non-standard locations. 486 487Perl actually inserts the following code: 488 489 BEGIN { 490 do { local $!; -f "$Config{sitelib}/sitecustomize.pl"; } 491 && do "$Config{sitelib}/sitecustomize.pl"; 492 } 493 494Since it is an actual C<do> (not a C<require>), F<sitecustomize.pl> 495doesn't need to return a true value. The code is run in package C<main>, 496in its own lexical scope. However, if the script dies, C<$@> will not 497be set. 498 499The value of C<$Config{sitelib}> is also determined in C code and not 500read from C<Config.pm>, which is not loaded. 501 502The code is executed I<very> early. For example, any changes made to 503C<@INC> will show up in the output of `perl -V`. Of course, C<END> 504blocks will be likewise executed very late. 505 506To determine at runtime if this capability has been compiled in your 507perl, you can check the value of C<$Config{usesitecustomize}>. 508 509=item B<-F>I<pattern> 510X<-F> 511 512specifies the pattern to split on for L</-a>. The pattern may be 513surrounded by C<//>, C<"">, or C<''>, otherwise it will be put in single 514quotes. You can't use literal whitespace or NUL characters in the pattern. 515 516B<-F> implicitly sets both L</-a> and L</-n>. 517 518=item B<-g> 519X<-g> 520 521undefines the input record separator (C<L<$E<sol>|perlvar/$E<sol>>>) and thus 522enables the slurp mode. In other words, it causes Perl to read whole 523files at once, instead of line by line. 524 525This flag is a simpler alias for L<-0777|/-0[octalE<sol>hexadecimal]>. 526 527Mnemonics: gobble, grab, gulp. 528 529=item B<-h> 530X<-h> 531 532prints a summary of the options. 533 534=item B<-?> 535X<-?> 536 537synonym for B<-h>: prints a summary of the options. 538 539=item B<-i>[I<extension>] 540X<-i> X<in-place> 541 542specifies that files processed by the C<E<lt>E<gt>> construct are to be 543edited in-place. It does this by renaming the input file, opening the 544output file by the original name, and selecting that output file as the 545default for print() statements. The extension, if supplied, is used to 546modify the name of the old file to make a backup copy, following these 547rules: 548 549If no extension is supplied, and your system supports it, the original 550I<file> is kept open without a name while the output is redirected to 551a new file with the original I<filename>. When perl exits, cleanly or not, 552the original I<file> is unlinked. 553 554If the extension doesn't contain a C<*>, then it is appended to the 555end of the current filename as a suffix. If the extension does 556contain one or more C<*> characters, then each C<*> is replaced 557with the current filename. In Perl terms, you could think of this 558as: 559 560 ($backup = $extension) =~ s/\*/$file_name/g; 561 562This allows you to add a prefix to the backup file, instead of (or in 563addition to) a suffix: 564 565 $ perl -pi'orig_*' -e 's/bar/baz/' fileA # backup to 566 # 'orig_fileA' 567 568Or even to place backup copies of the original files into another 569directory (provided the directory already exists): 570 571 $ perl -pi'old/*.orig' -e 's/bar/baz/' fileA # backup to 572 # 'old/fileA.orig' 573 574These sets of one-liners are equivalent: 575 576 $ perl -pi -e 's/bar/baz/' fileA # overwrite current file 577 $ perl -pi'*' -e 's/bar/baz/' fileA # overwrite current file 578 579 $ perl -pi'.orig' -e 's/bar/baz/' fileA # backup to 'fileA.orig' 580 $ perl -pi'*.orig' -e 's/bar/baz/' fileA # backup to 'fileA.orig' 581 582From the shell, saying 583 584 $ perl -p -i.orig -e "s/foo/bar/; ... " 585 586is the same as using the program: 587 588 #!/usr/bin/perl -pi.orig 589 s/foo/bar/; 590 591which is equivalent to 592 593 #!/usr/bin/perl 594 $extension = '.orig'; 595 LINE: while (<>) { 596 if ($ARGV ne $oldargv) { 597 if ($extension !~ /\*/) { 598 $backup = $ARGV . $extension; 599 } 600 else { 601 ($backup = $extension) =~ s/\*/$ARGV/g; 602 } 603 rename($ARGV, $backup); 604 open(ARGVOUT, ">$ARGV"); 605 select(ARGVOUT); 606 $oldargv = $ARGV; 607 } 608 s/foo/bar/; 609 } 610 continue { 611 print; # this prints to original filename 612 } 613 select(STDOUT); 614 615except that the B<-i> form doesn't need to compare $ARGV to $oldargv to 616know when the filename has changed. It does, however, use ARGVOUT for 617the selected filehandle. Note that STDOUT is restored as the default 618output filehandle after the loop. 619 620As shown above, Perl creates the backup file whether or not any output 621is actually changed. So this is just a fancy way to copy files: 622 623 $ perl -p -i'/some/file/path/*' -e 1 file1 file2 file3... 624or 625 $ perl -p -i'.orig' -e 1 file1 file2 file3... 626 627You can use C<eof> without parentheses to locate the end of each input 628file, in case you want to append to each file, or reset line numbering 629(see example in L<perlfunc/eof>). 630 631If, for a given file, Perl is unable to create the backup file as 632specified in the extension then it will skip that file and continue on 633with the next one (if it exists). 634 635For a discussion of issues surrounding file permissions and B<-i>, see 636L<perlfaq5/Why does Perl let me delete read-only files? Why does -i clobber 637protected files? Isn't this a bug in Perl?>. 638 639You cannot use B<-i> to create directories or to strip extensions from 640files. 641 642Perl does not expand C<~> in filenames, which is good, since some 643folks use it for their backup files: 644 645 $ perl -pi~ -e 's/foo/bar/' file1 file2 file3... 646 647Note that because B<-i> renames or deletes the original file before 648creating a new file of the same name, Unix-style soft and hard links will 649not be preserved. 650 651Finally, the B<-i> switch does not impede execution when no 652files are given on the command line. In this case, no backup is made 653(the original file cannot, of course, be determined) and processing 654proceeds from STDIN to STDOUT as might be expected. 655 656=item B<-I>I<directory> 657X<-I> X<@INC> 658 659Directories specified by B<-I> are prepended to the search path for 660modules (C<@INC>). 661 662=item B<-l>[I<octnum>] 663X<-l> X<$/> X<$\> 664 665enables automatic line-ending processing. It has two separate 666effects. First, it automatically chomps C<$/> (the input record 667separator) when used with L</-n> or L</-p>. Second, it assigns C<$\> 668(the output record separator) to have the value of I<octnum> so 669that any print statements will have that separator added back on. 670If I<octnum> is omitted, sets C<$\> to the current value of 671C<$/>. For instance, to trim lines to 80 columns: 672 673 perl -lpe 'substr($_, 80) = ""' 674 675Note that the assignment C<$\ = $/> is done when the switch is processed, 676so the input record separator can be different than the output record 677separator if the B<-l> switch is followed by a 678L<-0|/-0[octalE<sol>hexadecimal]> switch: 679 680 gnufind / -print0 | perl -ln0e 'print "found $_" if -p' 681 682This sets C<$\> to newline and then sets C<$/> to the null character. 683 684=item B<-m>[B<->]I<module> 685X<-m> X<-M> 686 687=item B<-M>[B<->]I<module> 688 689=item B<-M>[B<->]I<'module ...'> 690 691=item B<-[mM]>[B<->]I<module=arg[,arg]...> 692 693B<-m>I<module> executes C<use> I<module> C<();> before executing your 694program. This loads the module, but does not call its C<import> method, 695so does not import subroutines and does not give effect to a pragma. 696 697B<-M>I<module> executes C<use> I<module> C<;> before executing your 698program. This loads the module and calls its C<import> method, causing 699the module to have its default effect, typically importing subroutines 700or giving effect to a pragma. 701You can use quotes to add extra code after the module name, 702e.g., C<'-MI<MODULE> qw(foo bar)'>. 703 704If the first character after the B<-M> or B<-m> is a dash (B<->) 705then the 'use' is replaced with 'no'. 706This makes no difference for B<-m>. 707 708A little builtin syntactic sugar means you can also say 709B<-mI<MODULE>=foo,bar> or B<-MI<MODULE>=foo,bar> as a shortcut for 710B<'-MI<MODULE> qw(foo bar)'>. This avoids the need to use quotes when 711importing symbols. The actual code generated by B<-MI<MODULE>=foo,bar> is 712C<use module split(/,/,q{foo,bar})>. Note that the C<=> form 713removes the distinction between B<-m> and B<-M>; that is, 714B<-mI<MODULE>=foo,bar> is the same as B<-MI<MODULE>=foo,bar>. 715 716A consequence of the C<split> formulation 717is that B<-MI<MODULE>=number> never does a version check, 718unless C<I<MODULE>::import()> itself is set up to do a version check, which 719could happen for example if I<MODULE> inherits from L<Exporter>. 720 721=item B<-n> 722X<-n> 723 724causes Perl to assume the following loop around your program, which 725makes it iterate over filename arguments somewhat like I<sed -n> or 726I<awk>: 727 728 LINE: 729 while (<>) { 730 ... # your program goes here 731 } 732 733Note that the lines are not printed by default. See L</-p> to have 734lines printed. If a file named by an argument cannot be opened for 735some reason, Perl warns you about it and moves on to the next file. 736 737Also note that C<< <> >> passes command line arguments to 738L<perlfunc/open>, which doesn't necessarily interpret them as file names. 739See L<perlop> for possible security implications. 740 741Here is an efficient way to delete all files that haven't been modified for 742at least a week: 743 744 find . -mtime +7 -print | perl -nle unlink 745 746This is faster than using the B<-exec> switch of I<find> because you don't 747have to start a process on every filename found (but it's not faster 748than using the B<-delete> switch available in newer versions of I<find>. 749It does suffer from the bug of mishandling newlines in pathnames, which 750you can fix if you follow the example under 751L<-0|/-0[octalE<sol>hexadecimal]>. 752 753C<BEGIN> and C<END> blocks may be used to capture control before or after 754the implicit program loop, just as in I<awk>. 755 756=item B<-p> 757X<-p> 758 759causes Perl to assume the following loop around your program, which 760makes it iterate over filename arguments somewhat like I<sed>: 761 762 763 LINE: 764 while (<>) { 765 ... # your program goes here 766 } continue { 767 print or die "-p destination: $!\n"; 768 } 769 770If a file named by an argument cannot be opened for some reason, Perl 771warns you about it, and moves on to the next file. Note that the 772lines are printed automatically. An error occurring during printing is 773treated as fatal. To suppress printing use the L</-n> switch. A B<-p> 774overrides a B<-n> switch. 775 776C<BEGIN> and C<END> blocks may be used to capture control before or after 777the implicit loop, just as in I<awk>. 778 779=item B<-s> 780X<-s> 781 782enables rudimentary switch parsing for switches on the command 783line after the program name but before any filename arguments (or before 784an argument of B<-->). Any switch found there is removed from @ARGV and sets the 785corresponding variable in the Perl program, in the main package. The following program 786prints "1" if the program is invoked with a B<-xyz> switch, and "abc" 787if it is invoked with B<-xyz=abc>. 788 789 #!/usr/bin/perl -s 790 if ($xyz) { print "$xyz\n" } 791 792Do note that a switch like B<--help> creates the variable C<${-help}>, which is 793not compliant with C<use strict "refs">. Also, when using this option on a 794script with warnings enabled you may get a lot of spurious "used only once" 795warnings. For these reasons, use of B<-s> is discouraged. See L<Getopt::Long> 796for much more flexible switch parsing. 797 798=item B<-S> 799X<-S> 800 801makes Perl use the L</PATH> environment variable to search for the 802program unless the name of the program contains path separators. 803 804On some platforms, this also makes Perl append suffixes to the 805filename while searching for it. For example, on Win32 platforms, 806the ".bat" and ".cmd" suffixes are appended if a lookup for the 807original name fails, and if the name does not already end in one 808of those suffixes. If your Perl was compiled with C<DEBUGGING> turned 809on, using the L<-Dp|/-Dletters> switch to Perl shows how the search 810progresses. 811 812Typically this is used to emulate C<#!> startup on platforms that don't 813support C<#!>. It's also convenient when debugging a script that uses C<#!>, 814and is thus normally found by the shell's $PATH search mechanism. 815 816This example works on many platforms that have a shell compatible with 817Bourne shell: 818 819 #!/usr/bin/perl 820 eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}' 821 if 0; # ^ Run only under a shell 822 823The system ignores the first line and feeds the program to F</bin/sh>, 824which proceeds to try to execute the Perl program as a shell script. 825The shell executes the second line as a normal shell command, and thus 826starts up the Perl interpreter. On some systems $0 doesn't always 827contain the full pathname, so the L</-S> tells Perl to search for the 828program if necessary. After Perl locates the program, it parses the 829lines and ignores them because the check 'if 0' is never true. 830If the program will be interpreted by csh, you will need 831to replace C<${1+"$@"}> with C<$*>, even though that doesn't understand 832embedded spaces (and such) in the argument list. To start up I<sh> rather 833than I<csh>, some systems may have to replace the C<#!> line with a line 834containing just a colon, which will be politely ignored by Perl. Other 835systems can't control that, and need a totally devious construct that 836will work under any of I<csh>, I<sh>, or Perl, such as the following: 837 838 eval '(exit $?0)' && eval 'exec perl -wS $0 ${1+"$@"}' 839 & eval 'exec /usr/bin/perl -wS $0 $argv:q' 840 if 0; # ^ Run only under a shell 841 842If the filename supplied contains directory separators (and so is an 843absolute or relative pathname), and if that file is not found, 844platforms that append file extensions will do so and try to look 845for the file with those extensions added, one by one. 846 847On DOS-like platforms, if the program does not contain directory 848separators, it will first be searched for in the current directory 849before being searched for on the PATH. On Unix platforms, the 850program will be searched for strictly on the PATH. 851 852=item B<-t> 853X<-t> 854 855Like L</-T>, but taint checks will issue warnings rather than fatal 856errors. These warnings can now be controlled normally with C<no warnings 857qw(taint)>. 858 859B<Note: This is not a substitute for C<-T>!> This is meant to be 860used I<only> as a temporary development aid while securing legacy code: 861for real production code and for new secure code written from scratch, 862always use the real L</-T>. 863 864This has no effect if your perl was built without taint support. 865 866=item B<-T> 867X<-T> 868 869turns on "taint" so you can test them. Ordinarily 870these checks are done only when running setuid or setgid. It's a 871good idea to turn them on explicitly for programs that run on behalf 872of someone else whom you might not necessarily trust, such as CGI 873programs or any internet servers you might write in Perl. See 874L<perlsec> for details. For security reasons, this option must be 875seen by Perl quite early; usually this means it must appear early 876on the command line or in the C<#!> line for systems which support 877that construct. 878 879=item B<-u> 880X<-u> 881 882This switch causes Perl to dump core after compiling your 883program. You can then in theory take this core dump and turn it 884into an executable file by using the I<undump> program (not supplied). 885This speeds startup at the expense of some disk space (which you 886can minimize by stripping the executable). (Still, a "hello world" 887executable comes out to about 200K on my machine.) If you want to 888execute a portion of your program before dumping, use the C<CORE::dump()> 889function instead. Note: availability of I<undump> is platform 890specific and may not be available for a specific port of Perl. 891 892=item B<-U> 893X<-U> 894 895allows Perl to do unsafe operations. Currently the only "unsafe" 896operations are attempting to unlink directories while running as superuser 897and running setuid programs with fatal taint checks turned into warnings. 898Note that warnings must be enabled along with this option to actually 899I<generate> the taint-check warnings. 900 901=item B<-v> 902X<-v> 903 904prints the version and patchlevel of your perl executable. 905 906=item B<-V> 907X<-V> 908 909prints summary of the major perl configuration values and the current 910values of @INC. 911 912=item B<-V:>I<configvar> 913 914Prints to STDOUT the value of the named configuration variable(s), 915with multiples when your C<I<configvar>> argument looks like a regex (has 916non-letters). For example: 917 918 $ perl -V:libc 919 libc='/lib/libc-2.2.4.so'; 920 $ perl -V:lib. 921 libs='-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc'; 922 libc='/lib/libc-2.2.4.so'; 923 $ perl -V:lib.* 924 libpth='/usr/local/lib /lib /usr/lib'; 925 libs='-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc'; 926 lib_ext='.a'; 927 libc='/lib/libc-2.2.4.so'; 928 libperl='libperl.a'; 929 .... 930 931Additionally, extra colons can be used to control formatting. A 932trailing colon suppresses the linefeed and terminator ";", allowing 933you to embed queries into shell commands. (mnemonic: PATH separator 934":".) 935 936 $ echo "compression-vars: " `perl -V:z.*: ` " are here !" 937 compression-vars: zcat='' zip='zip' are here ! 938 939A leading colon removes the "name=" part of the response, this allows 940you to map to the name you need. (mnemonic: empty label) 941 942 $ echo "goodvfork="`./perl -Ilib -V::usevfork` 943 goodvfork=false; 944 945Leading and trailing colons can be used together if you need 946positional parameter values without the names. Note that in the case 947below, the C<PERL_API> params are returned in alphabetical order. 948 949 $ echo building_on `perl -V::osname: -V::PERL_API_.*:` now 950 building_on 'linux' '5' '1' '9' now 951 952=item B<-w> 953X<-w> 954 955prints warnings about dubious constructs, such as variable names 956mentioned only once and scalar variables used 957before being set; redefined subroutines; references to undefined 958filehandles; filehandles opened read-only that you are attempting 959to write on; values used as a number that don't I<look> like numbers; 960using an array as though it were a scalar; if your subroutines 961recurse more than 100 deep; and innumerable other things. 962 963This switch really just enables the global C<$^W> variable; normally, 964the lexically scoped C<use warnings> pragma is preferred. You 965can disable or promote into fatal errors specific warnings using 966C<__WARN__> hooks, as described in L<perlvar> and L<perlfunc/warn>. 967See also L<perldiag> and L<perltrap>. A fine-grained warning 968facility is also available if you want to manipulate entire classes 969of warnings; see L<warnings>. 970 971=item B<-W> 972X<-W> 973 974Enables all warnings regardless of C<no warnings> or C<$^W>. 975See L<warnings>. 976 977=item B<-X> 978X<-X> 979 980Disables all warnings regardless of C<use warnings> or C<$^W>. 981See L<warnings>. 982 983Forbidden in C<L</PERL5OPT>>. 984 985=item B<-x> 986X<-x> 987 988=item B<-x>I<directory> 989 990tells Perl that the program is embedded in a larger chunk of unrelated 991text, such as in a mail message. Leading garbage will be 992discarded until the first line that starts with C<#!> and contains the 993string "perl". Any meaningful switches on that line will be applied. 994 995All references to line numbers by the program (warnings, errors, ...) 996will treat the C<#!> line as the first line. 997Thus a warning on the 2nd line of the program, which is on the 100th 998line in the file will be reported as line 2, not as line 100. 999This can be overridden by using the C<#line> directive. 1000(See L<perlsyn/"Plain Old Comments (Not!)">) 1001 1002If a directory name is specified, Perl will switch to that directory 1003before running the program. The B<-x> switch controls only the 1004disposal of leading garbage. The program must be terminated with 1005C<__END__> if there is trailing garbage to be ignored; the program 1006can process any or all of the trailing garbage via the C<DATA> filehandle 1007if desired. 1008 1009The directory, if specified, must appear immediately following the B<-x> 1010with no intervening whitespace. 1011 1012=back 1013 1014=head1 ENVIRONMENT 1015X<perl, environment variables> 1016 1017=over 12 1018 1019=item HOME 1020X<HOME> 1021 1022Used if C<chdir> has no argument. 1023 1024=item LOGDIR 1025X<LOGDIR> 1026 1027Used if C<chdir> has no argument and L</HOME> is not set. 1028 1029=item PATH 1030X<PATH> 1031 1032Used in executing subprocesses, and in finding the program if L</-S> is 1033used. 1034 1035=item PERL5LIB 1036X<PERL5LIB> 1037 1038A list of directories in which to look for Perl library files before 1039looking in the standard library. 1040Any architecture-specific and version-specific directories, 1041such as F<version/archname/>, F<version/>, or F<archname/> under the 1042specified locations are automatically included if they exist, with this 1043lookup done at interpreter startup time. In addition, any directories 1044matching the entries in C<$Config{inc_version_list}> are added. 1045(These typically would be for older compatible perl versions installed 1046in the same directory tree.) 1047 1048If PERL5LIB is not defined, L</PERLLIB> is used. Directories are separated 1049(like in PATH) by a colon on Unixish platforms and by a semicolon on 1050Windows (the proper path separator being given by the command C<perl 1051-V:I<path_sep>>). 1052 1053When running taint checks, either because the program was running setuid or 1054setgid, or the L</-T> or L</-t> switch was specified, neither PERL5LIB nor 1055L</PERLLIB> is consulted. The program should instead say: 1056 1057 use lib "/my/directory"; 1058 1059=item PERL5OPT 1060X<PERL5OPT> 1061 1062Command-line options (switches). Switches in this variable are treated 1063as if they were on every Perl command line. Only the B<-[CDIMTUWdmtw]> 1064switches are allowed. When running taint checks (either because the 1065program was running setuid or setgid, or because the L</-T> or L</-t> 1066switch was used), this variable is ignored. If PERL5OPT begins with 1067B<-T>, tainting will be enabled and subsequent options ignored. If 1068PERL5OPT begins with B<-t>, tainting will be enabled, a writable dot 1069removed from @INC, and subsequent options honored. 1070 1071=item PERLIO 1072X<PERLIO> 1073 1074A space (or colon) separated list of PerlIO layers. If perl is built 1075to use PerlIO system for IO (the default) these layers affect Perl's IO. 1076 1077It is conventional to start layer names with a colon (for example, C<:perlio>) to 1078emphasize their similarity to variable "attributes". But the code that parses 1079layer specification strings, which is also used to decode the PERLIO 1080environment variable, treats the colon as a separator. 1081 1082An unset or empty PERLIO is equivalent to the default set of layers for 1083your platform; for example, C<:unix:perlio> on Unix-like systems 1084and C<:unix:crlf> on Windows and other DOS-like systems. 1085 1086The list becomes the default for I<all> Perl's IO. Consequently only built-in 1087layers can appear in this list, as external layers (such as C<:encoding()>) need 1088IO in order to load them! See L<"open pragma"|open> for how to add external 1089encodings as defaults. 1090 1091Layers it makes sense to include in the PERLIO environment 1092variable are briefly summarized below. For more details see L<PerlIO>. 1093 1094=over 8 1095 1096=item :crlf 1097X<:crlf> 1098 1099A layer which does CRLF to C<"\n"> translation distinguishing "text" and 1100"binary" files in the manner of MS-DOS and similar operating systems, 1101and also provides buffering similar to C<:perlio> on these architectures. 1102 1103=item :perlio 1104X<:perlio> 1105 1106This is a re-implementation of stdio-like buffering written as a 1107PerlIO layer. As such it will call whatever layer is below it for 1108its operations, typically C<:unix>. 1109 1110=item :stdio 1111X<:stdio> 1112 1113This layer provides a PerlIO interface by wrapping system's ANSI C "stdio" 1114library calls. The layer provides both buffering and IO. 1115Note that the C<:stdio> layer does I<not> do CRLF translation even if that 1116is the platform's normal behaviour. You will need a C<:crlf> layer above it 1117to do that. 1118 1119=item :unix 1120X<:unix> 1121 1122Low-level layer that calls C<read>, C<write>, C<lseek>, etc. 1123 1124=back 1125 1126The default set of layers should give acceptable results on all platforms. 1127 1128For Unix platforms that will be the equivalent of ":unix:perlio" or ":stdio". 1129Configure is set up to prefer the ":stdio" implementation if the system's library 1130provides for fast access to the buffer (not common on modern architectures); 1131otherwise, it uses the ":unix:perlio" implementation. 1132 1133On Win32 the default in this release (5.30) is ":unix:crlf". Win32's ":stdio" 1134has a number of bugs/mis-features for Perl IO which are somewhat depending 1135on the version and vendor of the C compiler. Using our own C<:crlf> layer as 1136the buffer avoids those issues and makes things more uniform. 1137 1138This release (5.30) uses C<:unix> as the bottom layer on Win32, and so still 1139uses the C compiler's numeric file descriptor routines. 1140 1141The PERLIO environment variable is completely ignored when Perl 1142is run in taint mode. 1143 1144=item PERLIO_DEBUG 1145X<PERLIO_DEBUG> 1146 1147If set to the name of a file or device when Perl is run with the 1148L<-Di|/-Dletters> command-line switch, the logging of certain operations 1149of the PerlIO subsystem will be redirected to the specified file rather 1150than going to stderr, which is the default. The file is opened in append 1151mode. Typical uses are in Unix: 1152 1153 % env PERLIO_DEBUG=/tmp/perlio.log perl -Di script ... 1154 1155and under Win32, the approximately equivalent: 1156 1157 > set PERLIO_DEBUG=CON 1158 perl -Di script ... 1159 1160This functionality is disabled for setuid scripts, for scripts run 1161with L</-T>, and for scripts run on a Perl built without C<-DDEBUGGING> 1162support. 1163 1164=item PERLLIB 1165X<PERLLIB> 1166 1167A list of directories in which to look for Perl library 1168files before looking in the standard library. 1169If L</PERL5LIB> is defined, PERLLIB is not used. 1170 1171The PERLLIB environment variable is completely ignored when Perl 1172is run in taint mode. 1173 1174=item PERL5DB 1175X<PERL5DB> 1176 1177The command used to load the debugger code. The default is: 1178 1179 BEGIN { require "perl5db.pl" } 1180 1181The PERL5DB environment variable is only used when Perl is started with 1182a bare L</-d> switch. 1183 1184=item PERL5DB_THREADED 1185X<PERL5DB_THREADED> 1186 1187If set to a true value, indicates to the debugger that the code being 1188debugged uses threads. 1189 1190=item PERL5SHELL (specific to the Win32 port) 1191X<PERL5SHELL> 1192 1193On Win32 ports only, may be set to an alternative shell that Perl must use 1194internally for executing "backtick" commands or system(). Default is 1195C<cmd.exe /x/d/c> on WindowsNT and C<command.com /c> on Windows95. The 1196value is considered space-separated. Precede any character that 1197needs to be protected, like a space or backslash, with another backslash. 1198 1199Note that Perl doesn't use COMSPEC for this purpose because 1200COMSPEC has a high degree of variability among users, leading to 1201portability concerns. Besides, Perl can use a shell that may not be 1202fit for interactive use, and setting COMSPEC to such a shell may 1203interfere with the proper functioning of other programs (which usually 1204look in COMSPEC to find a shell fit for interactive use). 1205 1206Before Perl 5.10.0 and 5.8.8, PERL5SHELL was not taint checked 1207when running external commands. It is recommended that 1208you explicitly set (or delete) C<$ENV{PERL5SHELL}> when running 1209in taint mode under Windows. 1210 1211=item PERL_ALLOW_NON_IFS_LSP (specific to the Win32 port) 1212X<PERL_ALLOW_NON_IFS_LSP> 1213 1214Set to 1 to allow the use of non-IFS compatible LSPs (Layered Service Providers). 1215Perl normally searches for an IFS-compatible LSP because this is required 1216for its emulation of Windows sockets as real filehandles. However, this may 1217cause problems if you have a firewall such as I<McAfee Guardian>, which requires 1218that all applications use its LSP but which is not IFS-compatible, because clearly 1219Perl will normally avoid using such an LSP. 1220 1221Setting this environment variable to 1 means that Perl will simply use the 1222first suitable LSP enumerated in the catalog, which keeps I<McAfee Guardian> 1223happy--and in that particular case Perl still works too because I<McAfee 1224Guardian>'s LSP actually plays other games which allow applications 1225requiring IFS compatibility to work. 1226 1227=item PERL_DEBUG_MSTATS 1228X<PERL_DEBUG_MSTATS> 1229 1230Relevant only if Perl is compiled with the C<malloc> included with the Perl 1231distribution; that is, if C<perl -V:d_mymalloc> is "define". 1232 1233If set, this dumps out memory statistics after execution. If set 1234to an integer greater than one, also dumps out memory statistics 1235after compilation. 1236 1237=item PERL_DESTRUCT_LEVEL 1238X<PERL_DESTRUCT_LEVEL> 1239 1240Controls the behaviour of global destruction of objects and other 1241references. See L<perlhacktips/PERL_DESTRUCT_LEVEL> for more information. 1242 1243=item PERL_DL_NONLAZY 1244X<PERL_DL_NONLAZY> 1245 1246Set to C<"1"> to have Perl resolve I<all> undefined symbols when it loads 1247a dynamic library. The default behaviour is to resolve symbols when 1248they are used. Setting this variable is useful during testing of 1249extensions, as it ensures that you get an error on misspelled function 1250names even if the test suite doesn't call them. 1251 1252=item PERL_ENCODING 1253X<PERL_ENCODING> 1254 1255If using the C<use encoding> pragma without an explicit encoding name, the 1256PERL_ENCODING environment variable is consulted for an encoding name. 1257 1258=item PERL_HASH_SEED 1259X<PERL_HASH_SEED> 1260 1261(Since Perl 5.8.1, new semantics in Perl 5.18.0) Used to override 1262the randomization of Perl's internal hash function. The value is expressed 1263in hexadecimal, and may include a leading 0x. Truncated patterns 1264are treated as though they are suffixed with sufficient 0's as required. 1265 1266If the option is provided, and C<PERL_PERTURB_KEYS> is NOT set, then 1267a value of '0' implies C<PERL_PERTURB_KEYS=0>/C<PERL_PERTURB_KEYS=NO> 1268and any other value implies 1269C<PERL_PERTURB_KEYS=2>/C<PERL_PERTURB_KEYS=DETERMINISTIC>. See the 1270documentation for L<PERL_PERTURB_KEYS|/PERL_PERTURB_KEYS> for important 1271caveats regarding the C<DETERMINISTIC> mode. 1272 1273B<PLEASE NOTE: The hash seed is sensitive information>. Hashes are 1274randomized to protect against local and remote attacks against Perl 1275code. By manually setting a seed, this protection may be partially or 1276completely lost. 1277 1278See L<perlsec/"Algorithmic Complexity Attacks">, L</PERL_PERTURB_KEYS>, and 1279L</PERL_HASH_SEED_DEBUG> for more information. 1280 1281=item PERL_PERTURB_KEYS 1282X<PERL_PERTURB_KEYS> 1283 1284(Since Perl 5.18.0) Set to C<"0"> or C<"NO"> then traversing keys 1285will be repeatable from run to run for the same C<PERL_HASH_SEED>. 1286Insertion into a hash will not change the order, except to provide 1287for more space in the hash. When combined with setting PERL_HASH_SEED 1288this mode is as close to pre 5.18 behavior as you can get. 1289 1290When set to C<"1"> or C<"RANDOM"> then traversing keys will be randomized. 1291Every time a hash is inserted into the key order will change in a random 1292fashion. The order may not be repeatable in a following program run 1293even if the PERL_HASH_SEED has been specified. This is the default 1294mode for perl when no PERL_HASH_SEED has been explicitly provided. 1295 1296When set to C<"2"> or C<"DETERMINISTIC"> then inserting keys into a hash 1297will cause the key order to change, but in a way that is repeatable from 1298program run to program run, provided that the same hash seed is used, 1299and that the code does not itself perform any non-deterministic 1300operations and also provided exactly the same environment context. 1301Adding or removing an environment variable may and likely will change 1302the key order. If any part of the code builds a hash using non- 1303deterministic keys, for instance a hash keyed by the stringified form of 1304a reference, or the address of the objects it contains, then this may 1305and likely will have a global effect on the key order of *every* hash in 1306the process. To work properly this setting MUST be coupled with the 1307L<PERL_HASH_SEED|/"PERL_HASH_SEED"> to produce deterministic results, 1308and in fact, if you do set the C<PERL_HASH_SEED> explicitly you do not 1309need to set this as well, it will be automatically set to this mode. 1310 1311B<NOTE:> Use of this option is considered insecure, and is intended only 1312for debugging non-deterministic behavior in Perl's hash function. Do 1313not use it in production. 1314 1315See L<perlsec/"Algorithmic Complexity Attacks"> and L</PERL_HASH_SEED> 1316and L</PERL_HASH_SEED_DEBUG> for more information. You can get and set the 1317key traversal mask for a specific hash by using the C<hash_traversal_mask()> 1318function from L<Hash::Util>. 1319 1320=item PERL_HASH_SEED_DEBUG 1321X<PERL_HASH_SEED_DEBUG> 1322 1323(Since Perl 5.8.1.) Set to C<"1"> to display (to STDERR) information 1324about the hash function, seed, and what type of key traversal 1325randomization is in effect at the beginning of execution. This, combined 1326with L</PERL_HASH_SEED> and L</PERL_PERTURB_KEYS> is intended to aid in 1327debugging nondeterministic behaviour caused by hash randomization. 1328 1329B<Note> that any information about the hash function, especially the hash 1330seed is B<sensitive information>: by knowing it, one can craft a denial-of-service 1331attack against Perl code, even remotely; see L<perlsec/"Algorithmic Complexity Attacks"> 1332for more information. B<Do not disclose the hash seed> to people who 1333don't need to know it. See also L<C<hash_seed()>|Hash::Util/hash_seed> and 1334L<C<hash_traversal_mask()>|Hash::Util/hash_traversal_mask>. 1335 1336An example output might be: 1337 1338 HASH_FUNCTION = ONE_AT_A_TIME_HARD HASH_SEED = 0x652e9b9349a7a032 PERTURB_KEYS = 1 (RANDOM) 1339 1340=item PERL_MEM_LOG 1341X<PERL_MEM_LOG> 1342 1343If your Perl was configured with B<-Accflags=-DPERL_MEM_LOG>, setting 1344the environment variable C<PERL_MEM_LOG> enables logging debug 1345messages. The value has the form C<< <I<number>>[m][s][t] >>, where 1346C<I<number>> is the file descriptor number you want to write to (2 is 1347default), and the combination of letters specifies that you want 1348information about (m)emory and/or (s)v, optionally with 1349(t)imestamps. For example, C<PERL_MEM_LOG=1mst> logs all 1350information to stdout. You can write to other opened file descriptors 1351in a variety of ways: 1352 1353 $ 3>foo3 PERL_MEM_LOG=3m perl ... 1354 1355=item PERL_ROOT (specific to the VMS port) 1356X<PERL_ROOT> 1357 1358A translation-concealed rooted logical name that contains Perl and the 1359logical device for the @INC path on VMS only. Other logical names that 1360affect Perl on VMS include PERLSHR, PERL_ENV_TABLES, and 1361SYS$TIMEZONE_DIFFERENTIAL, but are optional and discussed further in 1362L<perlvms> and in F<README.vms> in the Perl source distribution. 1363 1364=item PERL_SIGNALS 1365X<PERL_SIGNALS> 1366 1367Available in Perls 5.8.1 and later. If set to C<"unsafe">, the pre-Perl-5.8.0 1368signal behaviour (which is immediate but unsafe) is restored. If set 1369to C<safe>, then safe (but deferred) signals are used. See 1370L<perlipc/"Deferred Signals (Safe Signals)">. 1371 1372=item PERL_UNICODE 1373X<PERL_UNICODE> 1374 1375Equivalent to the L<-C|/-C [numberE<sol>list]> command-line switch. Note 1376that this is not a boolean variable. Setting this to C<"1"> is not the 1377right way to "enable Unicode" (whatever that would mean). You can use 1378C<"0"> to "disable Unicode", though (or alternatively unset PERL_UNICODE 1379in your shell before starting Perl). See the description of the 1380L<-C|/-C [numberE<sol>list]> switch for more information. 1381 1382=item PERL_USE_UNSAFE_INC 1383X<PERL_USE_UNSAFE_INC> 1384 1385If perl has been configured to not have the current directory in 1386L<C<@INC>|perlvar/@INC> by default, this variable can be set to C<"1"> 1387to reinstate it. It's primarily intended for use while building and 1388testing modules that have not been updated to deal with "." not being in 1389C<@INC> and should not be set in the environment for day-to-day use. 1390 1391=item SYS$LOGIN (specific to the VMS port) 1392X<SYS$LOGIN> 1393 1394Used if chdir has no argument and L</HOME> and L</LOGDIR> are not set. 1395 1396=item PERL_INTERNAL_RAND_SEED 1397X<PERL_INTERNAL_RAND_SEED> 1398 1399Set to a non-negative integer to seed the random number generator used 1400internally by perl for a variety of purposes. 1401 1402Ignored if perl is run setuid or setgid. Used only for some limited 1403startup randomization (hash keys) if C<-T> or C<-t> perl is started 1404with tainting enabled. 1405 1406Perl may be built to ignore this variable. 1407 1408=back 1409 1410Perl also has environment variables that control how Perl handles data 1411specific to particular natural languages; see L<perllocale>. 1412 1413Perl and its various modules and components, including its test frameworks, 1414may sometimes make use of certain other environment variables. Some of 1415these are specific to a particular platform. Please consult the 1416appropriate module documentation and any documentation for your platform 1417(like L<perlsolaris>, L<perllinux>, L<perlmacosx>, L<perlwin32>, etc) for 1418variables peculiar to those specific situations. 1419 1420Perl makes all environment variables available to the program being 1421executed, and passes these along to any child processes it starts. 1422However, programs running setuid would do well to execute the following 1423lines before doing anything else, just to keep people honest: 1424 1425 $ENV{PATH} = "/bin:/usr/bin"; # or whatever you need 1426 $ENV{SHELL} = "/bin/sh" if exists $ENV{SHELL}; 1427 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; 1428 1429=head1 ORDER OF APPLICATION 1430 1431Some options, in particular C<-I>, C<-M>, C<PERL5LIB> and C<PERL5OPT> can 1432interact, and the order in which they are applied is important. 1433 1434Note that this section does not document what I<actually> happens inside the 1435perl interpreter, it documents what I<effectively> happens. 1436 1437=over 1438 1439=item -I 1440 1441The effect of multiple C<-I> options is to C<unshift> them onto C<@INC> 1442from right to left. So for example: 1443 1444 perl -I 1 -I 2 -I 3 1445 1446will first prepend C<3> onto the front of C<@INC>, then prepend C<2>, and 1447then prepend C<1>. The result is that C<@INC> begins with: 1448 1449 qw(1 2 3) 1450 1451=item -M 1452 1453Multiple C<-M> options are processed from left to right. So this: 1454 1455 perl -Mlib=1 -Mlib=2 -Mlib=3 1456 1457will first use the L<lib> pragma to prepend C<1> to C<@INC>, then 1458it will prepend C<2>, then it will prepend C<3>, resulting in an C<@INC> 1459that begins with: 1460 1461 qw(3 2 1) 1462 1463=item the PERL5LIB environment variable 1464 1465This contains a list of directories, separated by colons. The entire list 1466is prepended to C<@INC> in one go. This: 1467 1468 PERL5LIB=1:2:3 perl 1469 1470will result in an C<@INC> that begins with: 1471 1472 qw(1 2 3) 1473 1474=item combinations of -I, -M and PERL5LIB 1475 1476C<PERL5LIB> is applied first, then all the C<-I> arguments, then all the 1477C<-M> arguments. This: 1478 1479 PERL5LIB=e1:e2 perl -I i1 -Mlib=m1 -I i2 -Mlib=m2 1480 1481will result in an C<@INC> that begins with: 1482 1483 qw(m2 m1 i1 i2 e1 e2) 1484 1485=item the PERL5OPT environment variable 1486 1487This contains a space separated list of switches. We only consider the 1488effects of C<-M> and C<-I> in this section. 1489 1490After normal processing of C<-I> switches from the command line, all 1491the C<-I> switches in C<PERL5OPT> are extracted. They are processed from 1492left to right instead of from right to left. Also note that while 1493whitespace is allowed between a C<-I> and its directory on the command 1494line, it is not allowed in C<PERL5OPT>. 1495 1496After normal processing of C<-M> switches from the command line, all 1497the C<-M> switches in C<PERL5OPT> are extracted. They are processed from 1498left to right, I<i.e.> the same as those on the command line. 1499 1500An example may make this clearer: 1501 1502 export PERL5OPT="-Mlib=optm1 -Iopti1 -Mlib=optm2 -Iopti2" 1503 export PERL5LIB=e1:e2 1504 perl -I i1 -Mlib=m1 -I i2 -Mlib=m2 1505 1506will result in an C<@INC> that begins with: 1507 1508 qw( 1509 optm2 1510 optm1 1511 1512 m2 1513 m1 1514 1515 opti2 1516 opti1 1517 1518 i1 1519 i2 1520 1521 e1 1522 e2 1523 ) 1524 1525=item Other complications 1526 1527There are some complications that are ignored in the examples above: 1528 1529=over 1530 1531=item arch and version subdirs 1532 1533All of C<-I>, C<PERL5LIB> and C<use lib> will also prepend arch and version 1534subdirs if they are present 1535 1536=item sitecustomize.pl 1537 1538=back 1539 1540=back 1541