📄 perlrun.pod
字号:
Also, in some platforms the C preprocessor knows too much: it knowsabout the C++ -style until-end-of-line comments starting with C<"//">.This will cause problems with common Perl constructs like s/foo//;because after -P this will became illegal code s/fooThe workaround is to use some other quoting separator than C<"/">,like for example C<"!">: s!foo!!;=item B<-s>enables rudimentary switch parsing for switches on the commandline after the program name but before any filename arguments (or beforean argument of B<-->). This means you can have switches with two leadingdashes (B<--help>). Any switch found there is removed from @ARGV and sets thecorresponding variable in the Perl program. The following programprints "1" if the program is invoked with a B<-xyz> switch, and "abc"if it is invoked with B<-xyz=abc>. #!/usr/bin/perl -s if ($xyz) { print "$xyz\n" }Do note that B<--help> creates the variable ${-help}, which is not compliantwith C<strict refs>.=item B<-S>makes Perl use the PATH environment variable to search for theprogram (unless the name of the program contains directory separators).On some platforms, this also makes Perl append suffixes to thefilename while searching for it. For example, on Win32 platforms,the ".bat" and ".cmd" suffixes are appended if a lookup for theoriginal name fails, and if the name does not already end in oneof those suffixes. If your Perl was compiled with DEBUGGING turnedon, using the -Dp switch to Perl shows how the search progresses.Typically this is used to emulate #! startup on platforms thatdon't support #!. This example works on many platforms thathave a shell compatible with Bourne shell: #!/usr/bin/perl eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}' if $running_under_some_shell;The system ignores the first line and feeds the program to F</bin/sh>,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 thusstarts up the Perl interpreter. On some systems $0 doesn't alwayscontain the full pathname, so the B<-S> tells Perl to search for theprogram if necessary. After Perl locates the program, it parses thelines and ignores them because the variable $running_under_some_shellis never true. If the program will be interpreted by csh, you will needto replace C<${1+"$@"}> with C<$*>, even though that doesn't understandembedded spaces (and such) in the argument list. To start up sh ratherthan csh, some systems may have to replace the #! line with a linecontaining just a colon, which will be politely ignored by Perl. Othersystems can't control that, and need a totally devious construct thatwill work under any of B<csh>, B<sh>, or Perl, such as the following: eval '(exit $?0)' && eval 'exec perl -wS $0 ${1+"$@"}' & eval 'exec /usr/bin/perl -wS $0 $argv:q' if $running_under_some_shell;If the filename supplied contains directory separators (i.e., is anabsolute or relative pathname), and if that file is not found,platforms that append file extensions will do so and try to lookfor the file with those extensions added, one by one.On DOS-like platforms, if the program does not contain directoryseparators, it will first be searched for in the current directorybefore being searched for on the PATH. On Unix platforms, theprogram will be searched for strictly on the PATH.=item B<-T>forces "taint" checks to be turned on so you can test them. Ordinarilythese checks are done only when running setuid or setgid. It's agood idea to turn them on explicitly for programs that run on behalfof someone else whom you might not necessarily trust, such as CGIprograms or any internet servers you might write in Perl. SeeL<perlsec> for details. For security reasons, this option must beseen by Perl quite early; usually this means it must appear earlyon the command line or in the #! line for systems which supportthat construct.=item B<-u>This obsolete switch causes Perl to dump core after compiling yourprogram. You can then in theory take this core dump and turn itinto an executable file by using the B<undump> program (not supplied).This speeds startup at the expense of some disk space (which youcan minimize by stripping the executable). (Still, a "hello world"executable comes out to about 200K on my machine.) If you want toexecute a portion of your program before dumping, use the dump()operator instead. Note: availability of B<undump> is platformspecific and may not be available for a specific port of Perl.This switch has been superseded in favor of the new Perl codegenerator backends to the compiler. See L<B> and L<B::Bytecode>for details.=item B<-U>allows Perl to do unsafe operations. Currently the only "unsafe"operations are the unlinking of directories while running as superuser,and running setuid programs with fatal taint checks turned intowarnings. Note that the B<-w> switch (or the C<$^W> variable) mustbe used along with this option to actually I<generate> thetaint-check warnings.=item B<-v>prints the version and patchlevel of your perl executable.=item B<-V>prints summary of the major perl configuration values and the currentvalues of @INC.=item B<-V:>I<name>Prints to STDOUT the value of the named configuration variable.For example, $ perl -V:man.dirwill provide strong clues about what your MANPATH variable shouldbe set to in order to access the Perl documentation.=item B<-w>prints warnings about dubious constructs, such as variable namesthat are mentioned only once and scalar variables that are usedbefore being set, redefined subroutines, references to undefinedfilehandles or filehandles opened read-only that you are attemptingto write on, values used as a number that doesn't look like numbers,using an array as though it were a scalar, if your subroutinesrecurse more than 100 deep, and innumerable other things.This switch really just enables the internal C<^$W> variable. Youcan disable or promote into fatal errors specific warnings usingC<__WARN__> hooks, as described in L<perlvar> and L<perlfunc/warn>.See also L<perldiag> and L<perltrap>. A new, fine-grained warningfacility is also available if you want to manipulate entire classesof warnings; see L<warnings> or L<perllexwarn>.=item B<-W>Enables all warnings regardless of C<no warnings> or C<$^W>.See L<perllexwarn>.=item B<-X>Disables all warnings regardless of C<use warnings> or C<$^W>.See L<perllexwarn>.=item B<-x> I<directory>tells Perl that the program is embedded in a larger chunk of unrelatedASCII text, such as in a mail message. Leading garbage will bediscarded until the first line that starts with #! and contains thestring "perl". Any meaningful switches on that line will be applied.If a directory name is specified, Perl will switch to that directorybefore running the program. The B<-x> switch controls only thedisposal of leading garbage. The program must be terminated withC<__END__> if there is trailing garbage to be ignored (the programcan process any or all of the trailing garbage via the DATA filehandleif desired).=back=head1 ENVIRONMENT=over 12=item HOMEUsed if chdir has no argument.=item LOGDIRUsed if chdir has no argument and HOME is not set.=item PATHUsed in executing subprocesses, and in finding the program if B<-S> isused.=item PERL5LIBA colon-separated list of directories in which to look for Perl libraryfiles before looking in the standard library and the currentdirectory. Any architecture-specific directories under the specifiedlocations are automatically included if they exist. If PERL5LIB is notdefined, PERLLIB is used.When running taint checks (either because the program was running setuidor setgid, or the B<-T> switch was used), neither variable is used.The program should instead say: use lib "/my/directory";=item PERL5OPTCommand-line options (switches). Switches in this variable are takenas if they were on every Perl command line. Only the B<-[DIMUdmw]>switches are allowed. When running taint checks (because the programwas running setuid or setgid, or the B<-T> switch was used), thisvariable is ignored. If PERL5OPT begins with B<-T>, tainting will beenabled, and any subsequent options ignored.=item PERLLIBA colon-separated list of directories in which to look for Perl libraryfiles before looking in the standard library and the current directory.If PERL5LIB is defined, PERLLIB is not used.=item PERL5DBThe command used to load the debugger code. The default is: BEGIN { require 'perl5db.pl' }=item PERL5SHELL (specific to the Win32 port)May be set to an alternative shell that perl must use internally forexecuting "backtick" commands or system(). Default is C<cmd.exe /x/c>on WindowsNT and C<command.com /c> on Windows95. The value is consideredto be space-separated. Precede any character that needs to be protected(like a space or backslash) with a backslash.Note that Perl doesn't use COMSPEC for this purpose becauseCOMSPEC has a high degree of variability among users, leading toportability concerns. Besides, perl can use a shell that may not befit for interactive use, and setting COMSPEC to such a shell mayinterfere with the proper functioning of other programs (which usuallylook in COMSPEC to find a shell fit for interactive use).=item PERL_DEBUG_MSTATSRelevant only if perl is compiled with the malloc included with the perldistribution (that is, if C<perl -V:d_mymalloc> is 'define').If set, this causes memory statistics to be dumped after execution. If setto an integer greater than one, also causes memory statistics to be dumpedafter compilation.=item PERL_DESTRUCT_LEVELRelevant only if your perl executable was built with B<-DDEBUGGING>,this controls the behavior of global destruction of objects and otherreferences.=item PERL_ROOT (specific to the VMS port)A translation concealed rooted logical name that contains perl and thelogical device for the @INC path on VMS only. Other logical names thataffect perl on VMS include PERLSHR, PERL_ENV_TABLES, and SYS$TIMEZONE_DIFFERENTIAL but are optional and discussed further in L<perlvms> and in F<README.vms> in the Perl source distribution.=item SYS$LOGIN (specific to the VMS port)Used if chdir has no argument and HOME and LOGDIR are not set.=backPerl also has environment variables that control how Perl handles dataspecific to particular natural languages. See L<perllocale>.Apart from these, Perl uses no other environment variables, exceptto make them available to the program being executed, and to childprocesses. However, programs running setuid would do well to executethe following lines before doing anything else, just to keep peoplehonest: $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)};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -