命令行大全

perl

瑞兹 发表于 2020-11-09 11:04浏览次数:

该perl命令是Perl 编程语言的解释器

查看英文版

目录:

1 perl 运行系统环境

2 perl 描述

3 运行Perl解释器

4 perl 语法

5 perl 环境

perl 运行系统环境

Linux

perl 描述

“ Perl”正式代表“实用提取和报告语言”。它最初是经过优化的语言,可用于扫描任意文本文件,从这些文本文件中提取信息并基于该信息打印报告。它很快成为许多系统管理任务的好语言。多年来,Perl已经发展成为一种通用的编程语言。从快速的“单行代码”到全面的应用程序开发,它被广泛使用。

该语言旨在实用(易于使用,高效,完整),而不是美观(小巧,优雅,简约)。它结合了sedawksh的一些最佳功能,从而使Unix用户熟悉并易于使用,以快速解决烦人的问题。它的通用编程工具支持过程,功能和面向对象的编程范例,使Perl成为大型项目的便捷语言。

多年以来,Perl在文本处理方面的根源一直未被忘记。它仍然拥有一些随处可见的最强大的正则表达式,并且它对Unicode文本的支持是世界一流的。它也通过大量扩展来处理各种结构化文本。这些由CPAN收集的库为现成的问题提供了现成的解决方案。

Perl的座右铭是“有多种方法可以做到这一点”。

"Perl" officially stands for "Practical Extraction and Report Language". It was originally a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It quickly became a good language for many system management tasks. Over the years, Perl has grown into a general-purpose programming language. It's widely used for everything from quick "one-liners" to full-scale application development.

The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). It combines some of the best features of sedawk, and sh, making it familiar and easy to use for Unix users to whip up quick solutions to annoying problems. Its general-purpose programming facilities support procedural, functional, and object-oriented programming paradigms, making Perl a comfortable language for major projects.

Perl's roots in text processing haven't been forgotten over the years. It still boasts some of the most powerful regular expressions to be found anywhere, and its support for Unicode text is world-class. It handles all kinds of structured text, too, through an extensive collection of extensions. Those libraries, collected in the CPAN, provide ready-made solutions to an astounding array of problems.

The Perl motto is "There's more than one way to do it."

查看英文版

查看中文版

运行Perl解释器

运行Perl程序的通常方法是使其直接可执行,或者通过在命令行上传递源文件的名称作为参数。(也可以使用交互式Perl环境。)启动后,Perl在以下位置之一查找程序:

  • 通过-e-E在命令行上逐行指定。
  • 包含在命令行中第一个文件名指定的文件中。(请注意,支持#!表示法的系统(例如bash)以这种方式调用解释器。)
  • 通过标准输入隐式传递。这仅在没有文件名参数的情况下有效-要将参数传递给STDIN读取的程序,必须为程序名称显式指定“ - ”。

使用方法2和3,除非您指定了-x开关,否则Perl从头开始分析输入文件,在这种情况下,它将扫描以#!开头的第一行并包含单词“ perl ”,然后从此处开始。这对于运行嵌入较大消息中的程序很有用。(在这种情况下,您将使用__END__令牌指示程序的结束。)

#!在解析线路时,总是检查线路的开关。因此,如果您使用的机器上只允许使用#!作为参数行,或更糟的是,甚至无法识别#!在第1行中,即使使用-x查找程序的开始,无论Perl如何被调用,您仍然可以获得一致的开关行为。

因为历史上有些操作系统默默地砍掉了的内核解释在32个字符之后的行中,某些开关可能会在命令行中传递,而某些则不会。如果您不小心的话,甚至可以得到一个不带字母的“ - ”。您可能要确保所有开关都落在该32个字符的边界之前或之后。大多数开关实际上并不关心是否进行了冗余处理,但是获得“ - ”而不是完整的开关可能会导致Perl尝试执行标准输入而不是程序。而部分-I开关也可能导致奇怪的结果。

一些开关确实关心它们是否被处理了两次,例如-l-0的组合。要么把所有开关32个字符边界之后(如果适用的话),或替换使用的-0位数BEGIN {$ / =“\ 0”; }

解析#!只要在该行中提到“ perl ”,开关就会启动。序列“ -* ”和“ - ”被特别忽略。

如果是#!该行不包含以#!命名的程序“ perl ”或“ indir ”一词执行而不是Perl解释器。这有点奇怪,但是它可以帮助不使用#的机器上的人,因为他们可以告诉程序其SHELL 环境变量为/ usr / bin / perl,然后Perl会将程序分派给它们的正确解释器。

找到程序后,Perl将整个程序编译为内部形式。如果有任何编译错误,则不尝试执行程序。(这与典型的shell脚本不同,后者可能会在发现语法错误之前部分运行。)

如果程序在语法上正确,则将执行该程序。如果程序运行到最后而没有命中exit()die()运算符,则提供隐式exit(0)表示成功完成。

Perl的位置

Perl可以位于您选择的任何位置,但是/ usr / bin / perl/ usr / local / bin / perl最好是实际二进制文件的符号链接。如果无法做到这一点,强烈建议系统管理员将与perl及其相关实用程序的符号链接放在通常沿着用户PATH或其他明显方便的目录中找到的目录中。

在本文档中,程序第一行上的#!/ usr / bin / perl将代表您系统上可用的任何方法。如果您关心特定的版本,建议使用特定的路径:

#!/usr/local/bin/perl5.14

或者,如果您只想运行(至少)某个版本,请在程序顶部放置如下语句:

use 5.014;

The normal way to run a Perl program is by making it directly executable, or else by passing the name of the source file as an argument on the command line. (An interactive Perl environment is also possible.) Upon startup, Perl looks for your program in one of the following places:

  • Specified line by line via -e or -E switches on the command line.
  • Contained in the file specified by the first filename on the command line. (Note that systems supporting the #! notation, such as bash, invoke interpreters this way.)
  • Passed in implicitly via standard input. This works only if there are no filename arguments--to pass arguments to a STDIN-read program you must explicitly specify a "-" for the program name.

With methods 2 and 3, Perl starts parsing the input file from the beginning, unless you've specified a -x switch, in which case it scans for the first line starting with #! and containing the word "perl", and starts there instead. This is useful for running a program embedded in a larger message. (In this case you would indicate the end of the program using the __END__ token.)

The #! line is always examined for switches as the line is being parsed. Thus, if you're on a machine that allows only one argument with the #! line, or worse, doesn't even recognize the #! line, you still can get consistent switch behaviour regardless of how Perl was invoked, even if -x was used to find the beginning of the program.

Because historically some operating systems silently chopped off kernel interpretation of the #! line after 32 characters, some switches may be passed in on the command line, and some may not; you could even get a "-" without its letter, if you're not careful. You probably want to make sure that all your switches fall either before or after that 32-character boundary. Most switches don't actually care if they're processed redundantly, but getting a "-" instead of a complete switch could cause Perl to try to execute standard input instead of your program. And a partial -I switch could also cause odd results.

Some switches do care if they are processed twice, for instance combinations of -l and -0. Either put all the switches after the 32-character boundary (if applicable), or replace the use of -0digits by BEGIN{ $/ = "\0digits"; }.

Parsing of the #! switches starts wherever "perl" is mentioned in the line. The sequences "-*" and "- " are specifically ignored.

If the #! line does not contain the word "perl" nor the word "indir" the program named after the #! is executed instead of the Perl interpreter. This is slightly bizarre, but it helps people on machines that don't do #!, because they can tell a program that their SHELL environment variable is /usr/bin/perl, and Perl will then dispatch the program to the correct interpreter for them.

After locating your program, Perl compiles the entire program to an internal form. If there are any compilation errors, execution of the program is not attempted. (This is unlike the typical shell script, which might run part-way through before finding a syntax error.)

If the program is syntactically correct, it is executed. If the program runs off the end without hitting an exit() or die() operator, an implicit exit(0) is provided to indicate successful completion.

Location Of Perl

Perl can be located wherever you choose, but it's best for both /usr/bin/perl and /usr/local/bin/perl to be symlinks to the actual binary. If that can't be done, system administrators are strongly encouraged to put symlinks to perl and its accompanying utilities into a directory typically found along a user's PATH, or in some other obvious and convenient place.

In this documentation, #!/usr/bin/perl on the first line of the program will stand in for whatever method works on your system. You are advised to use a specific path if you care about a specific version:

#!/usr/local/bin/perl5.14

or if you just want to be running (at least) a certain version, place a statement like this at the top of your program:

use 5.014;

查看英文版

查看中文版

perl 语法

perl [ -sTtuUWX ] [ -hv ] [ -V[:configvar] ] [ -cw ] [ -d[t][:debugger] ] 
     [ -D[number/list] ] [ -pna ] [ -Fpattern ] [ -l[octal] ] 
     [ -0[octal/hexadecimal] ] [ -Idir ] [ -m[-]module ] [ -M[-]'module...' ] 
     [ -f ] [ -C [number/list] ] [ -S ] [ -x[dir] ] [ -i[extension] ] 
     [ [-e|-E] 'command' ] [ -- ] [ programfile ] [ argument ]...

选件

perl接受以下命令行参数:

-0 [octal/hexadecimal] 将输入记录分隔符($ /)指定为八进制或十六进制数字。如果没有数字,则空字符为分隔符。其他开关可能在数字之前或之后。例如,如果您使用的find版本可以打印以空字符结尾的文件名,则可以这样说:

find . -name '* .orig'-print0 | perl -n0e unlnk
特殊值00将使Perl在段落模式下“抓取”文件。任何值为0400或更高的值都会使Perl吞噬整个文件,但是按照惯例,值0777是通常用于此目的的值。

您也可以使用十六进制符号指定分隔符:-0x HHH ...,其中H是有效的十六进制数字。与八进制格式不同,此格式可用于指定任何Unicode字符,甚至是0xFF之后的字符。因此,如果您确实想要0777的记录分隔符,请将其指定为-0x1FF。(这意味着您不能使用-x选项的目录名称由十六进制数字组成,否则Perl会认为您已将十六进制数字指定为-0。)
-a 与-n或-p一起使用时,打开自动拆分模式。对@F 数组的隐式split命令是由-n或-p生成的隐式while 循环内的第一件事。

perl -ane'print pop(@F),“ \ n”;'
相当于

while(<>){@F = split(''); print pop(@F),“ \ n”;}
可以使用-F指定替代分隔符。
-C [number/list] 的-C标志控制部分的Perl的Unicode功能。

从5.8.1开始,-C后面可以跟数字或选项字母列表。字母,它们的数值和效果如下:列出字母等于将数字相加。
letter number description
I 1 假定STDIN为UTF-8
O 2 STDOUT将采用UTF-8
E 4 STDERR将采用UTF-8
S 7 I+ O + E
i 8 UTF-8是输入流的默认PerlIO层
o 16 UTF-8是输出流的默认PerlIO层
D 24 I+O
A 32 的@ARGV预计元素被字符串以UTF-8编码的
L 64 通常,“ IOEioA ”是无条件的,L使其以语言环境环境变量(以优先级从高到低的顺序为LC_ALL,LC_TYPE和LANG)为条件-如果变量表示UTF-8,则选择的“ IOEioA ”有效
a 256 将$ {^ UTF8CACHE}设置为-1,以在调试模式下运行UTF-8缓存代码。
例如,-COE和1 -C 6将两者接通UTF-8岬在两个STDOUT和stderr。重复字母只是多余的,不是累积的或切换的。

该IO选项意味着任何后续的open() (或类似的I / O在当前文件范围操作)将有:UTF8 PerlIO的层隐式施加到它们,换句话说,UTF-8从任何输入流预期的,和UTF-8被生成到任何输出流。这仅仅是默认的,有明确层中的open() ,并用binmode()一个可以操纵流如常。

-C在自己的(后面没有任何数字或选项列表),或空字符串“”为PERL_UNICODE环境变量,具有相同的效果-CSDL。换句话说,标准I / O句柄和默认的open()层都是UTF-8格式的,但是仅当语言环境环境变量指示UTF-8语言环境时才适用。此行为遵循Perl 5.8.0的隐式(和有问题的)UTF-8行为。(请参阅perl581delta中UTF-8语言环境下的UTF-8不再是默认值。)

您可以使用-C0(或对于PERL_UNICODE为“ 0 ” )显式禁用所有上述Unicode功能。 只读魔术变量$ {^ UNICODE}

反映此设置的数值。此变量在Perl启动期间设置,此后为只读。如果需要运行时效果,请使用三参数open(),二参数binmode()和open编译指示。

(在早于5.8.1的Perls中,-C开关是一个仅Win32的开关,它启用了使用支持Unicode的“广泛的系统调用” Win32 API。但是,该功能实际上未被使用,因此命令行开关是“ 。回收”)

注:因为Perl 5.10.1,如果-C选项时所使用的#!行,它也必须在命令行上指定,因为在执行perl解释器时,已经设置了标准流。您还可以使用binmode()设置I / O流的编码。
-C 使Perl检查程序的语法,然后退出而不执行它。实际上,它将执行BEGIN,UNITCHECK或CHECK块以及任何use语句:这些被视为在程序执行之外发生。但是,INIT和END块将被跳过。
-d,-dt 在Perl调试器(perldebug)下运行程序。如果指定了t,则它向调试器指示正在调试的代码中将使用线程。
-d:MOD [=bar,baz]
-dt:MOD [=bar,baz]
在安装为Devel :: MOD的调试,概要分析或跟踪模块的控制下运行程序。例如,-d:DProf使用Devel :: DProf分析器执行程序。与-M标志一样,可以将选项传递到Devel :: MOD包,在其中Devel :: MOD :: import例程将接收并解释它们。再次,像-M一样,使用--d:-MOD调用Devel :: MOD :: unimport而不是import。以逗号分隔的选项列表必须后跟一个“ = ”字符。如果t 被指定,它向调试器指示将在正在调试的代码中使用线程。
-Dletters-Dnumber 设置调试标志。要查看它如何执行程序,请使用-Dtls。(这仅在将调试编译到Perl中时有效。)另一个不错的值是-Dx,它列出了已编译的语法树。而-Dr显示编译的正则表达式; 输出格式在perldebguts中进行了说明。

或者,指定数字而不是字母列表(例如,-D14等效于-Dtls):

number letter description
1 p 标记和解析(使用v,显示解析堆栈)
2 s 堆栈快照(使用v,显示所有堆栈)
4 l 上下文(循环)堆栈处理
8 t 跟踪执行
16 o 方法和重载分辨率
32 c 字符串/数字转换
64 P 打印配置文件信息,源文件输入状态
128 m 内存和SV分配
256 f 格式处理
512 r 正则表达式解析和执行
1024 x 语法树转储
2048 u 沾污检查
4096 U 非官方的用户黑客行为(仅供私人使用,未发布的用途)
8192 H 哈希转储-篡改values()
16384 X 便签本分配
32768 D 打扫干净
65536 S 作业平板分配
131072 T 代币化
262144 R 包括转储变量的引用计数(例如,使用-Ds时)
524288 J 在包DB中的操作码上显示s,t,P-debug(不要跳过)
1048576 v 详细:与其他标志一起使用
2097152 C 写时复制
4194304 A 内部结构一致性检查
8388608 q 安静-目前仅抑制“ EXECUTING ”消息
16777216 M 跟踪智能匹配分辨率
33554432 B 转储子程序定义,包括像BEGIN这样的特殊块
所有这些标志都需要-DDEBUGGING当你编译Perl可执行文件(但见:OPD在Devel::Peek或“debug”模式可能会改变这一点)。有关如何执行此操作,请参见Perl源代码发行版中的INSTALL文件。如果“配置”询问您有关优化器/调试器的标志时,如果包含-g选项,则会自动设置此标志。

如果您只是想在执行Perl代码的每一行中打印出内容(即sh -x为shell脚本提供的方式),则不能使用Perl的-D开关。而是这样做:

# If you have“ env”utility 
env PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS 
program  
#Bourne shell syntax 
PERLDB_OPTS =“ NonStop = 1 AutoTrace = 1 frame = 2” perl -dS 
program  
#csh syntax 
(setenv PERLDB_OPTS“ NonStop = 1 AutoTrace = 1 frame = 2”; 
perl -dS program) 
-e commandline 可以用来输入一行程序。如果给定-e,Perl将不在参数列表中查找文件名。可以使用多个-e命令来构建多行脚本。确保在普通程序中使用分号。
-E commandline 行为与-e一样,除了它隐式启用所有可选功能(在主编译单元中)。
-f 启动时禁用执行$ Config {sitelib} /sitecustomize.pl。

可以构建Perl,以使其默认情况下将在启动时尝试执行$ Config {sitelib} /sitecustomize.pl(在BEGIN块中)。这是允许系统管理员自定义Perl行为方式的挂钩。例如,它可以用于将条目添加到@INC数组,以使Perl在非标准位置查找模块。

Perl实际上插入了以下代码:

BEGIN{do{local$ !; -f" 
$ Config {sitelib} /sitecustomize.pl"; } &&do 
" $ Config {sitelib} /sitecustomize.pl";}
由于这是实际操作(而不是require),因此sitecustomize.pl不需要返回真实值。该代码在包main中以其自己的词法范围运行。但是,如果脚本死了,将不会设置$ @。

的值$配置{sitelib}也是在C代码确定,而不是从读Config.pm,这是不加载。

该代码很早执行。例如,对@INC所做的任何更改将显示在“ perl -V ”的输出中。当然,END块将同样执行到很晚。

要在运行时确定此功能是否已在perl中进行编译,可以检查$ Config {usesitecustomize}的值。
-Fpattern 如果-a也有效,则指定要分割的模式。该模式可以用//,“”或“”括起来,否则将用单引号引起来。您不能在模式中使用文字空白。
-H 打印选项摘要。
-i [extension] 指定由<>构造处理的文件要就地编辑。它通过重命名输入文件,使用原始名称打开输出文件并选择该输出文件作为print()语句的默认值来做到这一点。扩展名(如果提供)用于遵循以下规则修改旧文件的名称以制作备份副本:

如果未提供任何扩展名,并且您的系统支持扩展名,则在输出时原始文件将保持打开状态而没有名称被重定向到具有原始文件名的新文件。当perl的退出,干净与否,原始文件断开链接。

如果扩展名不包含*,那么它将作为后缀附加到当前文件名的末尾。如果扩展名确实包含一个或多个*字符,则每个*都将替换为当前文件名。用Perl来讲,您可以这样认为:

($ backup = $ extension)=`s/\*/$file_name/g;
这使您可以为备份文件添加前缀,而不是后缀(或除了后缀):

perl -pi'orig_ *'-e's/bar/baz/'fileA#backup to 
'orig_fileA'
甚至将原始文件的备份副本放置到另一个目录中(前提是该目录已存在):

perl -pi'old/*.orig'-e's/bar/baz/'fileA#backup to 
'old / fileA.orig'
这些单线套是等效的:

# overwrite current fileperl -pi -e's / bar / baz /'fileA # 
overwrite current fileperl -pi'*'-e's / bar / baz /'fileA
#backup to'fileA.orig'perl -pi'。 orig'-e's / bar / baz /'
fileA#backup to'fileA.orig'perl -pi'*。orig'-e
's / bar / baz /'fileA
从壳说

perl -p -i.orig -e“ s / foo / bar /; ...”
与使用该程序相同:

#!/ usr / bin / perl -pi.orig s / foo / bar /;
相当于

#!/ usr / bin / perl $ extension ='.orig'; LINE:while(<>){
if($ ARGV ne $ oldargv){if($ extension!〜/ \ * /){
$ backup = $ ARGV 。$extension;} else {($ backup = 
$ extension)=〜s / \ * / $ ARGV / g; }rename($ ARGV,$ backup); 
open(ARGVOUT,“> $ ARGV”); select(ARGVOUT); $ oldargv = 
$ ARGV; } s / foo / bar /;}continue{print;#this prints to 
original filename} select(STDOUT);
除了-i形式不需要将$ ARGV与$ oldargv进行比较以了解文件名何时已更改之外。但是,它确实将ARGVOUT用于选定的文件句柄。请注意,STDOUT将在循环后恢复为默认输出文件句柄。

如上所示,无论是否实际更改任何输出,Perl都会创建备份文件。因此,这只是复制文件的一种好方法:

perl -p -i'/ some / file / path / *'-e 1 file1 file2 file3 ...
要么

perl -p -i'.orig'-e 1 file1 file2 file3 ...
如果要附加到每个文件或重置行号,可以使用不带括号的eof定位每个输入文件的末尾。

如果对于给定的文件,Perl无法创建扩展名中指定的备份文件,则它将跳过该文件并继续执行下一个文件(如果存在)。

您不能使用-i创建目录或从文件中删除扩展名。

Perl不会在文件名中扩展〜,这很好,因为有些人将它用作备份文件:

perl -pi〜-e's / foo / bar /'file1 file2 file3 ...
请注意,由于-i在创建具有相同名称的新文件之前会重命名或删除原始文件,因此将不会保留Unix样式的软链接和硬链接。

最后,当命令行上未提供任何文件时,-i开关不会阻止执行。在这种情况下,不进行备份(当然不能确定原始文件),并且处理可能从STDIN进行到STDOUT。
-Idirectory -I指定的目录位于模块(@INC)的搜索路径之前。
-l [octnum] 启用自动行尾处理。它有两个单独的作用。首先,它自动格格小号$ /(输入记录分隔符)当用于-n或-p。其次,它将$ \(输出记录分隔符)分配为octnum的值,以便任何打印语句将重新添加该分隔符。如果省略octnum,则将$ \设置为$ /的当前值。例如,将行修剪为80列:

perl -lpe'substr($ _,80)=“”'
请注意,分配$ \ = $ /是在处理开关时完成的,因此,如果-l开关后接-0开关,则输入记录分隔符可以与输出记录分隔符不同:

gnufind / -print0 | perl -ln0e'print "found $_" if -p'
此套$ \来换行,然后设置$ /为空字符。

-m [ - ]module- 

M [ - ]module- 

M [ - ] 'module... ' -
[mM]
[-]module=arg[,arg ] ...

-m模块执行use 模块(); 在执行程序之前。

-M模块执行使用 模块 ;在执行程序之前。您可以使用引号在模块名称后添加额外的代码,例如'-M MODULE qw(foo bar )'。

如果-M或-m之后的第一个字符是破折号(-),则将' use '替换为' no '。

您也可以说-m MODULE = foo ,bar或-M MODULE = foo ,bar作为'-M MODULE qw(foo bar )'的快捷方式。这样可以避免在导入符号时使用引号。-M MODULE = foo ,bar生成的实际代码是使用模块split(/,/,q { foo ,bar })。请注意,=形式删除了-m和-M之间的区别。

结果是-M MODULE = number永远不会进行版本检查,除非将MODULE :: import()本身设置为进行版本检查,例如,如果MODULE继承自Exporter ,则可能发生这种情况。
-n 使Perl在您的程序周围假设以下循环,从而使其遍历文件名参数,如sed -n或awk:

LINE:while(<>){...#your program goes here}
请注意,默认情况下不打印行。请参阅-p以打印行。如果由于某种原因而无法打开由参数命名的文件,则Perl会警告您该文件,然后移至下一个文件。

另外,请注意,<>将命令行参数传递给open,并不一定会将其解释为文件名。

这是删除至少一个星期未修改的所有文件的有效方法:

find .-mtime +7 -print | perl -nle unlink
这比使用find的-exec开关快,因为您不必对找到的每个文件名都启动进程。它确实存在路径名中换行处理不当的错误,如果您遵循-0下的示例,则可以修复该错误。就像awk中一样,

BEGIN和END块可用于在隐式程序循环之前或之后捕获控制。
-p 使Perl在您的程序周围假设以下循环,从而使其遍历文件名参数,如sed:

LINE:while(<>){...#your program goes here
} continue{print or die "-p destination: $!\ n“;}
如果由于某种原因而无法打开由参数命名的文件,则Perl会警告您,然后移至下一个文件。请注意,这些行是自动打印的。在打印过程中发生的错误被视为致命错误。要禁止打印,请使用-n开关。甲-p覆盖一个-n开关。就像awk中一样,

BEGIN和END块可用于在隐式循环之前或之后捕获控制。
-s 在程序名称之后但在任何文件名参数之前(或参数“ - ”之前)启用命令行上的开关的基本开关解析。在那里找到的所有开关都将从@ARGV中删除,并在Perl程序中设置相应的变量。如果使用-xyz开关调用以下程序,则该程序将显示“ 1 ”,如果使用-xyz = abc调用该程序,则将显示“ abc ” 。

#!/ usr / bin / perl -sif($ xyz){print“ $ xyz \ n”}
请注意,类似--help的开关将创建变量$ { -help },该变量与使用严格的“ refs”不兼容。另外,在启用了警告的脚本上使用此选项时,您可能会收到很多虚假的“仅使用一次”警告。
-S 使Perl使用PATH环境变量来搜索程序,除非程序名称包含路径分隔符。

在某些平台上,这还使Perl在搜索文件名时将后缀附加到文件名。例如,在Win32平台上,如果对原始名称的查找失败,并且名称尚未以这些后缀之一结尾,则会附加“ .bat ”和“ .cmd ”后缀。如果在打开DEBUGGING的情况下编译了Perl ,则使用-Dp切换到Perl会显示搜索的进度。

通常,它用于模拟#!在不支持#的平台上启动!。在调试使用#!的脚本时也很方便。,因此通常是由外壳程序的$ PATH搜索机制找到的。

该示例可在具有与Bourne shell兼容的shell的许多平台上运行:

#!/ usr / bin / perleval'exec / usr / bin / perl -wS $ 0 $ 
{1+“ $ @ ”}'if$ running_under_some_shell;
系统将忽略第一行,并将程序提供给/ bin / sh,然后继续尝试将Perl程序作为shell脚本执行。该Shell作为常规Shell命令执行第二行,从而启动Perl解释器。在某些系统上,$ 0并不总是包含完整的路径名,因此-S告诉Perl必要时搜索程序。Perl找到程序后,它将分析行并忽略它们,因为变量$ running_under_some_shell永远不会为true。如果程序将由csh解释,则需要将$ {1+“ $ @ ”}替换为$ *,即使这样无法理解参数列表中的嵌入式空格(或类似内容)。要启动sh而不是csh,某些系统可能必须替换#!。行与仅包含冒号的行,Perl会礼貌地忽略它。其他系统无法控制它,并且需要一个完全弯曲的构造,该构造可以在csh,sh或perl的任何一种下工作,例如:

eval'(exit $?0)'&& eval'exec perl -wS $ 0 $ {1+“ $ @ ”}'&
eval'exec / usr / bin / perl -wS $ 0 $ argv:q'if
$ running_under_some_shell;
如果提供的文件名包含目录分隔符(因此是绝对路径或相对路径名),并且未找到该文件,则附加文件扩展名的平台会这样做,并尝试查找添加了这些扩展名的文件。

在类似DOS的平台上,如果程序不包含目录分隔符,则将首先在当前目录中搜索该程序,然后再在PATH上搜索该程序。在Unix平台上,将严格在PATH上搜索该程序。
-t 与-T相似,但污点检查将发出警告,而不是致命错误。现在可以正常地控制这些警告,而无需警告qw(taint)。

注意:这不能替代-T!这只能在保护遗留代码时用作临时开发工具:对于真实的生产代码和从头开始编写的新安全代码,请始终使用real -T。
-T 打开“污点”,以便您可以对其进行测试。通常,仅在运行setuid或setgid时才执行这些检查。最好为代表您可能不一定信任的其他人运行的程序(例如CGI程序或您可能在Perl中编写的任何Internet服务器)显式打开它们。出于安全原因,Perl必须很早就看到此选项。通常,这意味着它必须早在命令行或#!中出现!支持该构造的系统的生产线。
-u 此开关导致Perl在编译程序后转储核心。从理论上讲,您可以使用此核心转储,并使用undump程序将其转换为可执行文件。这样可以加快启动速度,但会占用一些磁盘空间(可以通过剥离可执行文件来最大程度地减少磁盘空间)。如果要在转储之前执行程序的一部分,请改用dump()运算符。注意:undump的可用性是特定于平台的。
-U 允许Perl执行不安全的操作。当前,仅有的“不安全”操作正在尝试以超级用户身份运行时运行取消目录链接,并且在运行带有致命污点检查的警告的setuid程序时。请注意,警告必须与该选项一起启用才能真正生成污点检查警告。
-v 打印您的perl可执行文件的版本和补丁级别。
-V 打印主要perl配置值和@INC当前值的摘要。
-V:configvar 当您的configvar参数看起来像正则表达式(具有非字母)时,将指定配置变量的值打印到STDOUT,并以倍数显示。例如:

perl -V:libc
libc ='/ lib / libc-2.2.4.so';
perl -V:lib。
libs ='-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc'; libc ='/ lib / libc-2.2.4.so';
perl -V:lib。*
libpth ='/ usr / local / lib / lib / usr / lib'; libs ='-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc'; lib_ext ='。a'; libc ='/ lib /libc-2.2.4.so';libperl='libperl.a'; .... 此外,多余的冒号可用于控制格式。尾部的冒号禁止换行和终止符“ ; ”,使您可以将查询嵌入到shell命令中。(助记符:PATH分隔符“ : ”。)

echo“ compression-vars:”`perl -V:z。*:`“are here!”
compression-vars:zcat =''zip ='zip' are here! 前导冒号会删除响应中的“ name = ”部分,这使您可以映射到所需的名称。(助记符:空标签)

echo“ goodvfork =”`./perl -Ilib -V :: usevfork`
goodvfork = false; 如果需要不带名称的位置参数值,则前导冒号和尾随冒号可以一起使用。请注意,在以下情况下,PERL_API 参数以字母顺序返回。

echo building_on `perl -V :: osname:-V :: PERL_API _。*:`now
building_on'linux''5''1''9'now
-w 打印有关可疑构造的警告,例如仅提及一次的变量名称和在设置之前使用的标量变量;重新定义的子例程;引用未定义的文件句柄;文件句柄打开了您尝试写的只读文件;用作数字的值看起来不像数字;使用数组,就好像它是一个标量;如果您的子例程递归深度超过100;和其他无数的东西。

这个开关实际上只是启用了全局$ ^ W变量。通常,首选词法范围的使用警告用法。您可以使用__WARN__挂钩将特定的警告禁用或升级为致命错误,如perlvar和warn中所述。另请参见perldiag和诱捕器。如果您要操纵整个警告类别,还可以使用细粒度的警告工具。
-W 使所有的警告,无论任何警告或$ ^ W。
-X 禁用所有警告不管用警告或$ ^ W。
-x -xdirectory 告诉Perl,该程序已嵌入到一大段无关的文本中,例如邮件中。前导垃圾将被丢弃,直到以#开头的第一行!并包含字符串“ perl ”。该行上任何有意义的开关都将被应用。

程序对行号的所有引用(警告,错误等)将视为#!行作为第一行。因此,程序第二行(文件中的第100行)的警告将报告为第2行,而不是第100行。可以通过使用#line指令覆盖该警告。

如果指定了目录名称,则Perl将在运行程序之前切换到该目录。该-x开关仅控制主要垃圾的处理。如果要忽略尾随垃圾,则该程序必须以__END__终止;如果需要,程序可以通过DATA文件句柄处理任何或所有尾随垃圾。

如果指定了该目录,则该目录必须立即出现在-x之后且中间没有空格。
perl [ -sTtuUWX ] [ -hv ] [ -V[:configvar] ] [ -cw ] [ -d[t][:debugger] ] 
     [ -D[number/list] ] [ -pna ] [ -Fpattern ] [ -l[octal] ] 
     [ -0[octal/hexadecimal] ] [ -Idir ] [ -m[-]module ] [ -M[-]'module...' ] 
     [ -f ] [ -C [number/list] ] [ -S ] [ -x[dir] ] [ -i[extension] ] 
     [ [-e|-E] 'command' ] [ -- ] [ programfile ] [ argument ]...

Options

perl accepts the following command-line arguments:

-0[octal/hexadecimal] specifies the input record separator ($/) as an octal or hexadecimal  number. If there are no digits, the null character is the separator. Other switches may precede or follow the digits. For example, if you have a version of find which can print filenames terminated by the null character, you can say this:

find . -name '*.orig' -print0 | perl -n0e unlink
The special value 00 will cause Perl to "slurp" files in paragraph mode. Any value 0400 or above will cause Perl to slurp files whole, but by convention the value 0777 is the one normally used for this purpose.

You can also specify the separator character using hexadecimal notation: -0xHHH..., where the H are valid hexadecimal digits. Unlike the octal form, this one may be used to specify any Unicode character, even those beyond 0xFF. So if you really want a record separator of 0777, specify it as -0x1FF. (This means that you cannot use the -x option with a directory name that consists of hexadecimal digits, or else Perl will think you have specified a hex number to -0.)
-a turns on autosplit mode when used with a -n or -p. An implicit split command to the @F array is done as the first thing inside the implicit while loop produced by the -n or -p.

perl -ane 'print pop(@F), "\n";'
is equivalent to

while (<>) { @F = split(' '); print pop(@F), "\n";}
An alternate delimiter may be specified using -F.
-C [number/list] The -C flag controls some of the Perl Unicode features.

As of 5.8.1, the -C can be followed either by a number or a list of option letters. The letters, their numeric values, and effects are as follows; listing the letters is equal to summing the numbers.

letter number description
I 1 STDIN is assumed to be in UTF-8
O 2 STDOUT will be in UTF-8
E 4 STDERR will be in UTF-8
S 7 I + O + E
i 8 UTF-8 is the default PerlIO layer for input streams
o 16 UTF-8 is the default PerlIO layer for output streams
D 24 i + o
A 32 the @ARGV elements are expected to be strings encoded in UTF-8
L 64 normally the "IOEioA" are unconditional, the L makes them conditional on the locale environment variables (the LC_ALLLC_TYPE, and LANG, in the order of decreasing precedence) -- if the variables indicate UTF-8, then the selected "IOEioA" are in effect
a 256 Set ${^UTF8CACHE} to -1, to run the UTF-8 caching code in debugging mode.
For example, -COE and -C6 will both turn on UTF-8-ness on both STDOUT and STDERR. Repeating letters is just redundant, not cumulative nor toggling.

The io options mean that any subsequent open() (or similar I/O operations) in the current file scope will have the :utf8 PerlIO layer implicitly applied to them, in other words, UTF-8 is expected from any input stream, and UTF-8 is produced to any output stream. This is just the default, with explicit layers in open() and with binmode() one can manipulate streams as usual.

-C on its own (not followed by any number or option list), or the empty string "" for the PERL_UNICODE environment variable, has the same effect as -CSDL. In other words, the standard I/O handles and the default open() layer are UTF-8-fied but only if the locale environment variables indicate a UTF-8 locale. This behaviour follows the implicit (and problematic) UTF-8 behaviour of Perl 5.8.0. (See UTF-8 no longer default under UTF-8 locales in perl581delta.)

You can use -C0 (or "0" for PERL_UNICODE ) to explicitly disable all the above Unicode features.

The read-only magic variable ${^UNICODE} reflects the numeric value of this setting. This variable is set during Perl startup and is thereafter read-only. If you want runtime effects, use the three-arg open(), the two-arg binmode(), and the open pragma.

(In Perls earlier than 5.8.1 the -C switch was a Win32-only switch that enabled the use of Unicode-aware "wide system call" Win32 APIs. This feature was practically unused, however, and the command line switch was therefore "recycled".)

Note: Since perl 5.10.1, if the -C option is used on the #! line, it must be specified on the command line as well, since the standard streams are already set up at this point in the execution of the perl interpreter. You can also use binmode() to set the encoding of an I/O stream.
-c causes Perl to check the syntax of the program and then exit without executing it. Actually, it will execute and BEGINUNITCHECK, or CHECK blocks and any use statements: these are considered as occurring outside the execution of your program. INIT and END blocks, however, will be skipped.
-d, -dt runs the program under the Perl debugger (perldebug). If t is specified, it indicates to the debugger that threads will be used in the code being debugged.
-d:MOD[=bar,baz]
-dt:MOD[=bar,baz]
runs the program under the control of a debugging, profiling, or tracing module installed as Devel::MOD. E.g., -d:DProf executes the program using the Devel::DProf profiler. As with the -M flag, options may be passed to the Devel::MOD package where they will be received and interpreted by the Devel::MOD::import routine. Again, like -M, use --d:-MOD to call Devel::MOD::unimport instead of import. The comma-separated list of options must follow a "=" character. If t is specified, it indicates to the debugger that threads will be used in the code being debugged.
-Dletters-Dnumber sets debugging flags. To watch how it executes your program, use -Dtls. (This works only if debugging is compiled into your Perl.) Another nice value is -Dx, which lists your compiled syntax tree. And -Dr displays compiled regular expressions; the format of the output is explained in perldebguts.

As an alternative, specify a number instead of list of letters (e.g., -D14 is equivalent to -Dtls):

number letter description
1 p Tokenizing and parsing (with v, displays parse stack)
2 s Stack snapshots (with v, displays all stacks)
4 l Context (loop) stack processing
8 t Trace execution
16 o Method and overloading resolution
32 c String/numeric conversions
64 P Print profiling info, source file input state
128 m Memory and SV allocation
256 f Format processing
512 r Regular expression parsing and execution
1024 x Syntax tree dump
2048 u Tainting checks
4096 U Unofficial, User hacking (reserved for private, unreleased use)
8192 H Hash dump -- usurps values()
16384 X Scratchpad allocation
32768 D Cleaning up
65536 S Op slab allocation
131072 T Tokenizing
262144 R Include reference counts of dumped variables (eg when using -Ds)
524288 J show s,t,P-debug (don't Jump over) on opcodes within package DB
1048576 v Verbose: use in conjunction with other flags
2097152 C Copy On Write
4194304 A Consistency checks on internal structures
8388608 q quiet - currently only suppresses the "EXECUTING" message
16777216 M trace smart match resolution
33554432 B dump subroutine definitions, including special blocks like BEGIN
All these flags require -DDEBUGGING when you compile the Perl executable (but see :opd in Devel::Peek or 'debug' mode in re which may change this). See the INSTALL file in the Perl source distribution for how to do this. This flag is automatically set if you include -g option when Configure asks you about optimizer/debugger flags.

If you're just trying to get a print out of each line of Perl code as it executes, the way that sh -x provides for shell scripts, you can't use Perl's -D switch. Instead do this:

# If you have "env" utility
env PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program
# Bourne shell syntax
PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program
# csh syntax
(setenv PERLDB_OPTS "NonStop=1 AutoTrace=1 frame=2"; perl -dS program)
-e commandline may be used to enter one line of program. If -e is given, Perl will not look for a filename in the argument list. Multiple -e commands may be given to build up a multi-line script. Make sure to use semicolons where you would in a normal program.
-E commandline behaves just like -e, except that it implicitly enables all optional features (in the main compilation unit).
-f Disable executing $Config{sitelib}/sitecustomize.pl at startup.

Perl can be built so that it by default will try to execute $Config{sitelib}/sitecustomize.pl at startup (in a BEGIN block). This is a hook that allows the sysadmin to customize how Perl behaves. It can for instance be used to add entries to the @INC array to make Perl find modules in non-standard locations.

Perl actually inserts the following code:

BEGIN { do { local $!; -f 
"$Config{sitelib}/sitecustomize.pl"; } && do
"$Config{sitelib}/sitecustomize.pl";}
Since it is an actual do (not a require), sitecustomize.pl doesn't need to return a true value. The code is run in package main, in its own lexical scope. However, if the script dies, $@ will not be set.

The value of $Config{sitelib} is also determined in C code and not read from Config.pm, which is not loaded.

The code is executed very early. For example, any changes made to @INC will show up in the output of "perl -V". Of course, END blocks will be likewise executed very late.

To determine at runtime if this capability has been compiled in your perl, you can check the value of $Config{usesitecustomize}.
-Fpattern specifies the pattern to split on if -a is also in effect. The pattern may be surrounded by // , "" , or '' , otherwise it will be put in single quotes. You can't use literal whitespace in the pattern.
-h prints a summary of the options.
-i[extension] specifies that files processed by the <> construct are to be edited in-place. It does this by renaming the input file, opening the output file by the original name, and selecting that output file as the default for print() statements. The extension, if supplied, is used to modify the name of the old file to make a backup copy, following these rules:

If no extension is supplied, and your system supports it, the original file is kept open without a name while the output is redirected to a new file with the original filename. When perl exits, cleanly or not, the original file is unlinked.

If the extension doesn't contain a *, then it is appended to the end of the current filename as a suffix. If the extension does contain one or more * characters, then each * is replaced with the current filename. In Perl terms, you could think of this as:

($backup = $extension) =~ s/\*/$file_name/g;
This allows you to add a prefix to the backup file, instead of (or in addition to) a suffix:

perl -pi'orig_*' -e 's/bar/baz/' fileA # backup to 
'orig_fileA'
Or even to place backup copies of the original files into another directory (provided the directory already exists):

perl -pi'old/*.orig' -e 's/bar/baz/' fileA  # backup to
'old/fileA.orig'
These sets of one-liners are equivalent:

# overwrite current fileperl -pi -e 's/bar/baz/' fileA # 
overwrite current fileperl -pi'*' -e 's/bar/baz/' 
fileA # backup to 'fileA.orig'perl -pi'.orig' -e 's/bar/baz/' fileA # backup to 
'fileA.orig'perl -pi'*.orig' -e
's/bar/baz/' fileA
From the shell, saying

perl -p -i.orig -e "s/foo/bar/; ... "
is the same as using the program:

#!/usr/bin/perl -pi.orig s/foo/bar/;
which is equivalent to

#!/usr/bin/perl$extension = '.orig';LINE: while (<>) { 
if ($ARGV ne $oldargv)  { if ($extension !~ /\*/)  { 
$backup = $ARGV . $extension; } else  { ($backup = 
$extension) =~ s/\*/$ARGV/g; } rename($ARGV, $backup); 
open(ARGVOUT, ">$ARGV"); select(ARGVOUT); $oldargv = 
$ARGV; } s/foo/bar/;}continue { print;	# this prints to 
original filename}select(STDOUT);
except that the -i form doesn't need to compare $ARGV to $oldargv to know when the filename has changed. It does, however, use ARGVOUT for the selected file handle. Note that STDOUT is restored as the default output file handle after the loop.

As shown above, Perl creates the backup file whether or not any output is actually changed. So this is just a fancy way to copy files:

perl -p -i'/some/file/path/*' -e 1 file1 file2 file3...
or

perl -p -i'.orig' -e 1 file1 file2 file3...
You can use eof without parentheses to locate the end of each input file, in case you want to append to each file, or reset line numbering.

If, for a given file, Perl is unable to create the backup file as specified in the extension then it will skip that file and continue on with the next one (if it exists).

You cannot use -i to create directories or to strip extensions from files.

Perl does not expand ~ in filenames, which is good, since some folks use it for their backup files:

perl -pi~ -e 's/foo/bar/' file1 file2 file3...
Note that because -i renames or deletes the original file before creating a new file of the same name, Unix-style soft and hard links will not be preserved.

Finally, the -i switch does not impede execution when no files are given on the command line. In this case, no backup is made (the original file cannot, of course, be determined) and processing proceeds from STDIN to STDOUT as might be expected.
-Idirectory Directories specified by -I are prepended to the search path for modules (@INC ).
-l[octnum] enables automatic line-ending processing. It has two separate effects. First, it automatically chomp$/ (the input record separator) when used with -n or -p. Second, it assigns $\ (the output record separator) to have the value of octnum so that any print statements will have that separator added back on. If octnum is omitted, sets $\ to the current value of $/. For instance, to trim lines to 80 columns:

perl -lpe 'substr($_, 80) = ""'
Note that the assignment $\ = $/ is done when the switch is processed, so the input record separator can be different than the output record separator if the -l switch is followed by a -0 switch:

gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
This sets $\ to newline and then sets $/ to the null character.
-m[-]module-
M
[-]module-
M
[-]'module ...' -
[mM]
[-]module=arg[,arg]...
-mmodule executes use module(); before executing your program.

-Mmodule executes use module ; before executing your program. You can use quotes to add extra code after the module name, e.g., '-MMODULE qw(foo bar)'.

If the first character after the -M or -m is a dash (-) then the 'use' is replaced with 'no'.

You can also say -mMODULE=foo,bar or -MMODULE=foo,bar as a shortcut for '-MMODULE qw(foo bar)'. This avoids the need to use quotes when importing symbols. The actual code generated by -MMODULE=foo,bar is use module split(/,/,q{foo,bar}). Note that the = form removes the distinction between -m and -M.

A consequence of this is that -MMODULE=number never does a version check, unless MODULE::import() itself is set up to do a version check, which could happen for example if MODULE inherits from Exporter.
-n causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed -n or awk:

LINE: while (<>) { ...# your program goes 
here}
Note that the lines are not printed by default. See -p to have lines printed. If a file named by an argument cannot be opened for some reason, Perl warns you about it and moves on to the next file.

Also, note that <> passes command line arguments to open, which doesn't necessarily interpret them as file names.

Here is an efficient way to delete all files that haven't been modified for at least a week:

find . -mtime +7 -print | perl -nle unlink
This is faster than using the -exec switch of find because you don't have to start a process on every filename found. It does suffer from the bug of mishandling newlines in pathnames, which you can fix if you follow the example under -0.

BEGIN and END blocks may be used to capture control before or after the implicit program loop, just as in awk.
-p causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed:

LINE: while (<>) { ...# your program goes here 
} continue { print or die "-p destination: $!\n";}
If a file named by an argument cannot be opened for some reason, Perl warns you about it, and moves on to the next file. Note that the lines are printed automatically. An error occurring during printing is treated as fatal. To suppress printing use the -n switch. A -p overrides a -n switch.

BEGIN and END blocks may be used to capture control before or after the implicit loop, just as in awk.
-s enables rudimentary switch parsing for switches on the command line after the program name but before any filename arguments (or before an argument of "--"). Any switch found there is removed from @ARGV and sets the corresponding variable in the Perl program. The following program prints "1" if the program is invoked with a -xyz switch, and "abc" if it is invoked with -xyz=abc.

#!/usr/bin/perl -sif ($xyz) { print "$xyz\n" }
Do note that a switch like --help creates the variable ${-help}, which is not compliant with use strict "refs". Also, when using this option on a script with warnings enabled you may get a lot of spurious "used only once" warnings.
-S< makes Perl use the PATH environment variable to search for the program unless the name of the program contains path separators.

On some platforms, this also makes Perl append suffixes to the filename while searching for it. For example, on Win32 platforms, the ".bat" and ".cmd" suffixes are appended if a lookup for the original name fails, and if the name does not already end in one of those suffixes. If your Perl was compiled with DEBUGGING turned on, using the -Dp switch to Perl shows how the search progresses.

Typically this is used to emulate #! startup on platforms that don't support #!. It's also convenient when debugging a script that uses #!, and is thus normally found by the shell's $PATH search mechanism.

This example works on many platforms that have a shell compatible with Bourne shell:

#!/usr/bin/perleval 'exec /usr/bin/perl -wS $0 
${1+"$@"}'if $running_under_some_shell;
The system ignores the first line and feeds the program to /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 thus starts up the Perl interpreter. On some systems $0 doesn't always contain the full pathname, so the -S tells Perl to search for the program if necessary. After Perl locates the program, it parses the lines and ignores them because the variable $running_under_some_shell is never true. If the program will be interpreted by csh, you will need to replace ${1+"$@"} with $*, even though that doesn't understand embedded spaces (and such) in the argument list. To start up sh rather than csh, some systems may have to replace the #! line with a line containing just a colon, which will be politely ignored by Perl. Other systems can't control that, and need a totally devious construct that will work under any of cshsh, 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 (and so is an absolute or relative pathname), and if that file is not found, platforms that append file extensions will do so and try to look for the file with those extensions added, one by one.

On DOS-like platforms, if the program does not contain directory separators, it will first be searched for in the current directory before being searched for on the PATH. On Unix platforms, the program will be searched for strictly on the PATH.
-t Like -T, but taint checks will issue warnings rather than fatal errors. These warnings can now be controlled normally with no warnings qw(taint).

Note: This is not a substitute for -T! This is meant to be used only as a temporary development aid while securing legacy code: for real production code and for new secure code written from scratch, always use the real -T.
-T turns on "taint" so you can test them. Ordinarily these checks are done only when running setuid or setgid. It's a good idea to turn them on explicitly for programs that run on behalf of someone else whom you might not necessarily trust, such as CGI programs or any Internet servers you might write in Perl. For security reasons, this option must be seen by Perl quite early; usually this means it must appear early on the command line or in the #! line for systems which support that construct.
-u This switch causes Perl to dump core after compiling your program. You can then in theory take this core dump and turn it into an executable file by using the undump program. This speeds startup at the expense of some disk space (which you can minimize by stripping the executable). If you want to execute a portion of your program before dumping, use the dump() operator instead. Note: availability of undump is platform specific.
-U allows Perl to do unsafe operations. Currently the only "unsafe" operations are attempting to unlink directories while running as superuser and running setuid programs with fatal taint checks turned into warnings. Note that warnings must be enabled along with this option to actually generate the taint-check warnings.
-v prints the version and patchlevel of your perl executable.
-V prints summary of the major perl configuration values and the current values of @INC.
-V:configvar Prints to STDOUT the value of the named configuration variable(s), with multiples when your configvar argument looks like a regex (has non-letters). For example:

perl -V:libc
libc='/lib/libc-2.2.4.so';
perl -V:lib.
libs='-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc';libc='/lib/libc-2.2.4.so';
perl -V:lib.*
libpth='/usr/local/lib /lib /usr/lib';libs='-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc';lib_ext='.a';libc='/lib/libc-2.2.4.so';libperl='libperl.a';.... Additionally, extra colons can be used to control formatting. A trailing colon suppresses the linefeed and terminator ";", allowing you to embed queries into shell commands. (mnemonic: PATH separator ":".)

echo "compression-vars: " `perl -V:z.*: ` " are here !"
compression-vars: zcat='' zip='zip' are here ! A leading colon removes the "name=" part of the response, this allows you to map to the name you need. (mnemonic: empty label)

echo "goodvfork="`./perl -Ilib -V::usevfork`
goodvfork=false; Leading and trailing colons can be used together if you need positional parameter values without the names. Note that in the case below, the PERL_API parameters are returned in alphabetical order.

echo building_on `perl -V::osname: -V::PERL_API_.*:` now
building_on 'linux' '5' '1' '9' now
-w prints warnings about dubious constructs, such as variable names mentioned only once and scalar variables used before being set; redefined subroutines; references to undefined file handles; file handles opened read-only that you are attempting to write on; values used as a number that don't look like numbers; using an array as though it were a scalar; if your subroutines recurse more than 100 deep; and innumerable other things.

This switch really just enables the global $^W variable; normally, the lexically scoped use warnings pragma is preferred. You can disable or promote into fatal errors specific warnings using __WARN__ hooks, as described in perlvar and warn. See also perldiag and perltrap. A fine-grained warning facility is also available if you want to manipulate entire classes of warnings.
-W Enables all warnings regardless of no warnings or $^W.
-X Disables all warnings regardless of use warnings or $^W.
-x-xdirectory tells Perl that the program is embedded in a larger chunk of unrelated text, such as in a mail message. Leading garbage will be discarded until the first line that starts with #! and contains the string "perl". Any meaningful switches on that line will be applied.

All references to line numbers by the program (warnings, errors, ...) will treat the #! line as the first line. Thus a warning on the 2nd line of the program, which is on the 100th line in the file will be reported as line 2, not as line 100. This can be overridden by using the #line directive.

If a directory name is specified, Perl will switch to that directory before running the program. The -x switch controls only the disposal of leading garbage. The program must be terminated with __END__ if there is trailing garbage to be ignored; the program can process any or all of the trailing garbage via the DATA file handle if desired.

The directory, if specified, must appear immediately following the -x with no intervening whitespace.

查看英文版

查看中文版

perl 环境

以下环境变量会影响perl的操作:

HOME
如果chdir没有参数,则使用它。
LOVDIR
如果chdir没有参数并且未设置HOME,则使用此参数。
PATH
如果使用-S,则用于执行子过程以及查找程序。
PERL5LIB
在标准库和当前目录中查找之前,要在其中查找Perl库文件的目录列表。如果存在特定于架构的版本和特定于版本的目录,例如指定位置下的version / archname /version /archname /,则会自动包含这些目录,并且在解释器启动时进行此查找。此外,还会添加与$ Config {inc_version_list}中的条目匹配的所有目录。(这些通常是用于安装在同一个目录树中旧的兼容perl的版本)。

如果PERL5LIB没有定义,PERLLIB使用。目录是分开的(例如在PATH中),在类似Unix的平台上用冒号表示,在Windows上用分号表示(正确的路径分隔符由命令perl -V:path_sep给出)。

在运行taint检查时,由于程序正在运行setuid或setgid,或者已指定-T-t开关,因此未查询PERL5LIBPERLLIB。该程序应改为:

使用lib“ / my / directory”;
PERL5OPT
命令行选项(开关)。将此变量中的开关当作在每个Perl命令行上一样。仅允许使用- [ CDIMUdmtwW ]开关。运行taint检查时(由于程序正在运行setuid或setgid,或者因为使用了-T-t开关),将忽略此变量。如果PERL5OPT-T开头,则将启用污点,而忽略后续选项。如果PERL5OPT-t开头,将启用污点处理,从@INC删除可写点,并接受后续选项。
PERLIO
用空格(或冒号)分隔的PerlIO层列表。如果将perl构建为将PerlIO系统用于IO(默认值),则这些层会影响Perl的IO。

通常以冒号(例如:perlio)开头图层名称,以强调其与变量“属性”的相似性。但是,解析层规范字符串的代码(也用于解码PERLIO环境变量)将冒号视为分隔符。

设置或为空的PERLIO等效于平台的默认层集;例如:UNIX:PerlIO的类Unix系统:UNIX:CRLF在Windows和其他DOS般的系统。

该列表成为所有Perl IO的默认列表。因此,只有内置层可以出现在此列表中,因为外部层(例如:encoding())需要IO来加载它们。有关如何添加外部编码作为默认值,请参见open pragma。以下简要概述了

可以包含在PERLIO环境变量中的各层。有关更多详细信息,请参见PerlIO

:bytes 伪图层,它关闭下面的图层的:utf8标志;本身在全局PERLIO环境变量中不太有用。你也许在想的:CRLF:bytes:PerlIO:bytes
:crlf 以MS-DOS和类似操作系统的方式执行CRLF到“ \ n ”转换以区分“文本”和“二进制”文件的层。(就将Control-Z视为文件结束标记而言,它目前并未模仿MS-DOS 。)
:mmap 通过使用mmap使整个文件出现在进程的地址空间中,然后将其用作PerlIO的“缓冲区” ,从而实现文件的“读取”层。
:perlio 这是写为PerlIO层的类stdio缓冲的重新实现。这样,它将调用其下面的任何层进行操作,通常是:unix
:pop 实验性伪图层,可删除最顶层。使用时应与硝酸甘油相同。
:raw 操纵其他层的伪层。应用:raw层等效于调用binmode($ fh)。它使流按原样传递每个字节而无需转换。特别是,CRLF转换和从区域设置intuiting:utf8均被禁用。

与早期版本的Perl不同,:raw不仅是:crlf的反面:其他会影响流二进制性质的层也将被删除或禁用。
:stdio 该层通过包装系统的ANSI C “ stdio”库调用来提供PerlIO接口。该层同时提供缓冲和IO。注意::stdio层不执行CRLF转换,即使这是平台的正常行为。为此,您将需要一个:crlf层。
:unix 调用readwritelseek等的低层。
:utf8 一个伪层,该伪层使下面的层中的标志能够告诉Perl输出应该在utf8中,并且应该认为输入已经是有效的utf8形式。警告:它不会检查有效性,因此输入时应格外谨慎,因为使用非最短的UTF-8编码等可能会发生安全违规。通常::encoding(utf8)是读取UTF-时的最佳选择8个编码数据。
:win32 在Win32平台上,该实验层使用本机“处理” IO,而不是类似Unix的数字文件描述符层。已知在5.14版中存在错误。
默认的图层集应在所有平台上都可以接受。

对于Unix平台,相当于“ unix perlio ”或“ stdio ”。如果系统的库提供了对缓冲区的快速访问,则将Configure设置为首选“ stdio ”实现。否则,它将使用“ unix perlio ”实现。

在Win32上,此版本(5.14)中的默认值为“ unix crlf ”。Win32的“ stdio ”具有许多Perl IO的错误/错误功能,这在一定程度上取决于C编译器的版本和供应商。使用我们自己的crlf层作为缓冲区可以避免这些问题,并使事情更加统一。crlf层提供CRLF转换以及缓冲。

当前版本(截至撰写本文时为5.14)使用UNIX作为Win32的底层,因此仍使用C编译器的数字文件描述符例程。有一个实验性的本机win32层,有望得到增强,最终应成为Win32下的默认层。当Perl在taint模式下运行时

PERLIO环境变量将被完全忽略。
PERLIO_DEBUG
如果设置为文件或设备的名称,则PerlIO子系统的某些操作将记录到该文件中,该文件以追加模式打开。典型用途是在Unix中:

env PERLIO_DEBUG = / dev / tty perl script...
在Win32下,大约等效:

set PERLIO_DEBUG = CONperl script...
对于setuid脚本和-T运行的脚本,此功能被禁用。
PERLLIB
在标准库和当前目录中查找之前,要在其中查找Perl库文件的目录列表。如果PERL5LIB定义,PERLLIB不被使用。当Perl在taint模式下运行时

PERLLIB环境变量将被完全忽略。
PERL5DB
用于加载调试器代码的命令。默认值为:

BEGIN{require “ perl5db.pl”}
所述PERL5DB当开始与裸Perl环境变量仅用于-d开关。
PERL5DB_THREADED
如果设置为true值,则向调试器指示正在调试的代码使用线程。
PERL5SHELL
(特定于Win32端口。)仅在Win32端口上,可以设置为Perl必须在内部用于执行“ backtick”命令或system()的备用Shell 。默认为CMD.EXE / X / d / C上的Windows NT和command.com / C上的Windows95。该值被视为以空格分隔。在需要保护的任何字符(例如空格或反斜杠)之前都应加上另一个反斜杠。

请注意,Perl不为此目的使用COMSPEC,因为COMSPEC在用户之间具有高度的可变性,从而导致可移植性问题。此外,Perl可以使用可能不适合交互式使用的外壳,而将COMSPEC设置为这样的外壳可能会干扰其他程序的正常运行(通常在COMSPEC中寻找适合交互式使用的外壳)。

在Perl 5.10.0和5.8.8之前,运行外部命令时不会对PERL5SHELL进行污染检查。在Windows下以异味模式运行时,建议您显式设置(或删除)$ ENV {PERL5SHELL}
PERL_ALLOW_NON_IFS_LSP
(特定于Win32端口。)设置为1以允许使用非IFS兼容的LSP(分层服务提供商)。Perl通常会搜索与IFS兼容的LSP,因为将Windows套接字模拟为真实文件句柄时,这是必需的。但是,如果您拥有诸如McAfee Guardian之类的防火墙,则这可能会引起问题,该防火墙要求所有应用程序都使用其LSP,但它不兼容IFS,因为显然Perl通常会避免使用这种LSP。

将此环境变量设置为1意味着Perl将使用目录中列举的第一个合适的LSP,这使McAfee Guardian保持满意,在这种情况下,Perl仍然有效,因为McAfee Guardian的LSP实际上在玩其他游戏,允许需要IFS兼容性的应用程序工作。
PERL_DEBUG_MSTATS
仅当使用Perl发行版中包含的malloc编译Perl时才相关;也就是说,如果perl -V:d_mymalloc为“ define ”。

如果设置,则执行后转储内存统计信息。如果设置为大于1的整数,则编译后还会转出内存统计信息。
PERL_DESTRUCT_LEVEL
仅当您的Perl可执行文件是使用-DDEBUGGING构建的时,此选项才相关。
PERL_DL_NONLAZY
设置为“ 1 ”可使Perl在加载动态库时解析所有未定义的符号。默认行为是在使用符号时解析它们。设置此变量在扩展测试期间很有用,因为即使在测试套件未调用它们的情况下,它也可以确保您在拼写错误的函数名称上遇到错误。
PERL_ENCODING
如果使用不带显式编码名称的使用编码用法,则将在PERL_ENCODING环境变量中查询编码名称。
PERL_HASH_SEED
(自Perl 5.8.1起,在Perl 5.18.0中提供了新的语义)用于覆盖Perl内部哈希函数的随机化。该值以十六进制表示,并且可以包含前导0x。截断的模式将被视为后缀,并根据需要添加足够的0

如果提供了该选项,并且设置PERL_PERTURB_KEYS,则值“ 0 ”表示PERL_PERTURB_KEYS = 0,其他任何值表示PERL_PERTURB_KEYS = 2

请注意:哈希种子是敏感信息。哈希是随机分配的,以防止针对Perl代码的本地和远程攻击。通过手动设置种子,此保护可能会部分或完全丢失。
PERL_PERTURB_KEYS
(从Perl 5.18.0开始)设置为“ 0 ”或“ NO ”,则对于相同的PERL_HASH_SEED,遍历遍历遍历键将是可重复的。插入到哈希中不会改变顺序,除非在哈希中提供更多空间。与设置PERL_HASH_SEED结合使用时,此模式将尽可能接近5.18之前的行为。

当设置为“ 1 ”或“ RANDOM ”时,遍历键将被随机化。每次将哈希插入密钥顺序时,都会以随机方式更改。即使已指定PERL_HASH_SEED,该顺序在以后的程序运行中也可能无法重复。这是perl的默认模式。

当设置为““或” DETERMINISTIC “,然后将键插入到哈希中将导致键顺序发生变化,但是这种方式在程序运行到程序运行之间是可重复的。

注意:此选项的使用被认为是不安全的,并且仅用于调试非-Perl哈希函数中的确定性行为,请勿在生产中使用它。

PERL_HASH_SEED_DEBUG
(自Perl 5.8.1开始。)设置为“ 1 ”以显示(到STDERR)有关散列函数,种子以及在执行开始时有效的密钥遍历随机类型的信息。结合PERL_HASH_SEEDPERL_PERTURB_KEYS可以帮助调试由哈希随机化引起的不确定行为。

请注意,有关散列函数的任何信息,特别是散列种子的信息都是敏感信息:通过了解该信息,甚至可以远程对Perl代码进行拒绝服务攻击。不要将哈希种子透露给不需要知道的人。另请参见hash_seed()key_traversal_mask()Hash::的Util

示例输出可能是:

HASH_FUNCTION = ONE_AT_A_TIME_HARD HASH_SEED = 
0x652e9b9349a7a032 PERTURB_KEYS = 1(RANDOM)
PERL_MEM_LOG
如果您的Perl配置了-Accflags = -DPERL_MEM_LOG,则设置环境变量PERL_MEM_LOG将启用日志记录调试消息。该值的格式为number > [ m ] [ s ] [ t ],其中number是要写入的文件描述符号(默认为2),字母组合指定您需要有关(m)的信息emory和/或(s)v,可选地包含(t)imestamp。例如,PERL_MEM_LOG = 1mst将所有信息记录到stdout。您可以通过多种方式写入其他打开的文件描述符:

$ 3> foo3 PERL_MEM_LOG = 3m perl ...
PERL_ROOT
(特定于VMS端口。)仅在VMS上包含Perl和@INC路径的逻辑设备的,隐藏在翻译后的根逻辑名称。在VMS上影响Perl的其他逻辑名称包括PERLSHRPERL_ENV_TABLESSYS $ TIMEZONE_DIFFERENTIAL,但它们是可选的,并在perlvms和Perl源代码发行版的README.vms中进行了进一步讨论。
PERL_SIGNALS
在Perls 5.8.1和更高版本中可用。如果设置为“ unsafe ”,则将还原Perl-5.8.0之前的信号行为(立即但不安全)。如果设置为安全,则使用安全(但延迟)信号。
PERL_UNICODE
等效于-C命令行开关。请注意,这不是布尔变量。将其设置为“ 1 ”不是“启用Unicode”的正确方法。但是,您可以使用“ 0 ”来“禁用Unicode”(或者在启动Perl之前在您的shell中取消设置PERL_UNICODE)。有关更多信息,请参见-C开关的描述。
SYS$LOGIN
(特定于VMS端口。)如果chdir没有参数,并且未设置HOMELOGDIR,则使用。

Perl及其各种模块和组件(包括其测试框架)有时可能会使用某些其他环境变量。其中一些特定于特定平台。请查阅适当的模块说明文件以及适用于您平台的任何说明文件,以了解这些特定情况所特有的变量。

Perl使所有环境变量可用于正在执行的程序,并将它们传递给它启动的任何子进程。但是,运行setuid的程序最好在执行其他操作之前执行以下行,只是为了使人们诚实:

$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)};

The following environment variables affect the operation of perl:

HOME
Used if chdir has no argument.
LOGDIR
Used if chdir has no argument and HOME is not set.
PATH
Used in executing subprocesses, and in finding the program if -S is used.
PERL5LIB
A list of directories in which to look for Perl library files before looking in the standard library and the current directory. Any architecture-specific and version-specific directories, such as version/archname/version/, or archname/ under the specified locations are automatically included if they exist, with this lookup done at interpreter startup time. Also, any directories matching the entries in $Config{inc_version_list} are added. (These typically would be for older compatible perl versions installed in the same directory tree.)

If PERL5LIB is not defined, PERLLIB is used. Directories are separated (like in PATH) by a colon on Unix-like platforms and by a semicolon on Windows (the proper path separator being given by the command perl -V:path_sep).

When running taint checks, either because the program was running setuid or setgid, or the -T or -t switch was specified, neither PERL5LIB nor PERLLIB is consulted. The program should instead say:

use lib "/my/directory";
PERL5OPT
Command-line options (switches). Switches in this variable are treated as if they were on every Perl command line. Only the -[CDIMUdmtwW] switches are allowed. When running taint checks (either because the program was running setuid or setgid, or because the -T or -t switch was used), this variable is ignored. If PERL5OPT begins with -T, tainting will be enabled and subsequent options ignored. If PERL5OPT begins with -t, tainting will be enabled, a writable dot removed from @INC, and subsequent options honored.
PERLIO
A space (or colon) separated list of PerlIO layers. If perl is built to use PerlIO system for IO (the default) these layers affect Perl's IO.

It is conventional to start layer names with a colon (for example, :perlio) to emphasize their similarity to variable "attributes". But the code that parses layer specification strings, which is also used to decode the PERLIO environment variable, treats the colon as a separator.

An unset or empty PERLIO is equivalent to the default set of layers for your platform; for example, :unix:perlio on Unix-like systems and :unix:crlf on Windows and other DOS-like systems.

The list becomes the default for all Perl's IO. Consequently only built-in layers can appear in this list, as external layers (such as :encoding() ) need IO to load them. See open pragma for how to add external encodings as defaults.

Layers that make sense to include in the PERLIO environment variable are briefly summarized below. For more details see PerlIO.

:bytes A pseudo layer that turns the :utf8 flag off for the layer below; unlikely to be useful on its own in the global PERLIO environment variable. You perhaps were thinking of :crlf:bytes or :perlio:bytes.
:crlf A layer which does CRLF to "\n" translation distinguishing "text" and "binary" files in the manner of MS-DOS and similar operating systems. (It currently does not mimic MS-DOS as far as treating of Control-Z as being an end-of-file marker.)
:mmap A layer that implements "reading" of files by using mmap to make an entire file appear in the process's address space, and then using that as PerlIO's "buffer".
:perlio This is a re-implementation of stdio-like buffering written as a PerlIO layer. As such it will call whatever layer is below it for its operations, typically :unix.
:pop An experimental pseudo layer that removes the topmost layer. Use with the same care as is reserved for nitroglycerin.
:raw A pseudo layer that manipulates other layers. Applying the :raw layer is equivalent to calling binmode($fh). It makes the stream pass each byte as-is without translation. In particular, both CRLF translation and intuiting :utf8 from the locale are disabled.

Unlike in earlier versions of Perl, :raw is not just the inverse of :crlf : other layers which would affect the binary nature of the stream are also removed or disabled.
:stdio This layer provides a PerlIO interface by wrapping system's ANSI C "stdio" library calls. The layer provides both buffering and IO. Note that the :stdio layer does not do CRLF translation even if that is the platform's normal behaviour. You will need a :crlf layer above it to do that.
:unix Low-level layer that calls readwritelseek, etc.
:utf8 A pseudo layer that enables a flag in the layer below to tell Perl that output should be in utf8 and that input should be regarded as already in valid utf8 form. WARNING: It does not check for validity and as such should be handled with extreme caution for input, because security violations can occur with non-shortest UTF-8 encodings, etc. Generally :encoding(utf8) is the best option when reading UTF-8 encoded data.
:win32 On Win32 platforms this experimental layer uses native "handle" IO rather than a Unix-like numeric file descriptor layer. Known to be buggy in release 5.14.
The default set of layers should give acceptable results on all platforms.

For Unix platforms that will be the equivalent of "unix perlio" or "stdio". Configure is set up to prefer the "stdio" implementation if the system's library provides for fast access to the buffer; otherwise, it uses the "unix perlio" implementation.

On Win32 the default in this release (5.14) is "unix crlf". Win32's "stdio" has a number of bugs/mis-features for Perl IO which are somewhat depending on the version and vendor of the C compiler. Using our own crlf layer as the buffer avoids those issues and makes things more uniform. The crlf layer provides CRLF conversion as well as buffering.

The current release (5.14 as of this writing) uses unix as the bottom layer on Win32, and so still uses the C compiler's numeric file descriptor routines. There is an experimental native win32 layer, which is expected to be enhanced and should eventually become the default under Win32.

The PERLIO environment variable is completely ignored when Perl is run in taint mode.
PERLIO_DEBUG
If set to the name of a file or device, certain operations of PerlIO subsystem will be logged to that file, which is opened in append mode. Typical uses are in Unix:

env PERLIO_DEBUG=/dev/tty perl script ...
and under Win32, the approximately equivalent:

set PERLIO_DEBUG=CONperl script ...
This functionality is disabled for setuid scripts and for scripts run with -T.
PERLLIB
A list of directories in which to look for Perl library files before looking in the standard library and the current directory. If PERL5LIB is defined, PERLLIB is not used.

The PERLLIB environment variable is completely ignored when Perl is run in taint mode.
PERL5DB
The command used to load the debugger code. The default is:

BEGIN { require "perl5db.pl" }
The PERL5DB environment variable is only used when Perl is started with a bare -d switch.
PERL5DB_THREADED
If set to a true value, indicates to the debugger that the code being debugged uses threads.
PERL5SHELL
(specific to the Win32 port.) On Win32 ports only, may be set to an alternative shell that Perl must use internally for executing "backtick" commands or system(). Default is cmd.exe /x/d/c on Windows NT and command.com /c on Windows95. The value is considered space-separated. Precede any character that needs to be protected, like a space or backslash, with another backslash.

Note that Perl doesn't use COMSPEC for this purpose because COMSPEC has a high degree of variability among users, leading to portability concerns. Besides, Perl can use a shell that may not be fit for interactive use, and setting COMSPEC to such a shell may interfere with the proper functioning of other programs (which usually look in COMSPEC to find a shell fit for interactive use).

Before Perl 5.10.0 and 5.8.8, PERL5SHELL was not taint checked when running external commands. It is recommended that you explicitly set (or delete) $ENV{PERL5SHELL} when running in taint mode under Windows.
PERL_ALLOW_NON_IFS_LSP
(specific to the Win32 port.) Set to 1 to allow the use of non-IFS compatible LSPs (Layered Service Providers). Perl normally searches for an IFS-compatible LSP because this is required for its emulation of Windows sockets as real file handles. However, this may cause problems if you have a firewall such as McAfee Guardian, which requires that all applications use its LSP but that is not IFS-compatible, because clearly Perl will normally avoid using such an LSP.

Setting this environment variable to 1 means that Perl will use the first suitable LSP enumerated in the catalog, which keeps McAfee Guardian happy, and in that particular case Perl still works too because McAfee Guardian's LSP actually plays other games which allow applications requiring IFS compatibility to work.
PERL_DEBUG_MSTATS
Relevant only if Perl is compiled with the malloc included with the Perl distribution; that is, if perl -V:d_mymalloc is "define".

If set, this dumps out memory statistics after execution. If set to an integer greater than one, also dumps out memory statistics after compilation.
PERL_DESTRUCT_LEVEL
Relevant only if your Perl executable was built with -DDEBUGGING, this controls the behaviour of global destruction of objects and other references.
PERL_DL_NONLAZY
Set to "1" to have Perl resolve all undefined symbols when it loads a dynamic library. The default behaviour is to resolve symbols when they are used. Setting this variable is useful during testing of extensions, as it ensures that you get an error on misspelled function names even if the test suite doesn't call them.
PERL_ENCODING
If using the use encoding pragma without an explicit encoding name, the PERL_ENCODING environment variable is consulted for an encoding name.
PERL_HASH_SEED
(Since Perl 5.8.1, new semantics in Perl 5.18.0) Used to override the randomization of Perl's internal hash function. The value is expressed in hexadecimal, and may include a leading 0x. Truncated patterns are treated as though they are suffixed with sufficient 0's as required.

If the option is provided, and PERL_PERTURB_KEYS is NOT set, then a value of '0' implies PERL_PERTURB_KEYS=0 and any other value implies PERL_PERTURB_KEYS=2.

PLEASE NOTE: The hash seed is sensitive information. Hashes are randomized to protect against local and remote attacks against Perl code. By manually setting a seed, this protection may be partially or completely lost.
PERL_PERTURB_KEYS
(Since Perl 5.18.0) Set to "0" or "NO" then traversing keys will be repeatable from run to run for the same PERL_HASH_SEED. Insertion into a hash will not change the order, except to provide for more space in the hash. When combined with setting PERL_HASH_SEED this mode is as close to pre 5.18 behavior as you can get.

When set to "1" or "RANDOM" then traversing keys will be randomized. Every time a hash is inserted into the key order will change in a random fashion. The order may not be repeatable in a following program run even if the PERL_HASH_SEED has been specified. This is the default mode for perl.

When set to "2" or "DETERMINISTIC" then inserting keys into a hash will cause the key order to change, but in a way that is repeatable from program run to program run.

NOTE: Use of this option is considered insecure, and is intended only for debugging non-deterministic behavior in Perl's hash function. Do not use it in production.

PERL_HASH_SEED_DEBUG
(Since Perl 5.8.1.) Set to "1" to display (to STDERR) information about the hash function, seed, and what type of key traversal randomization is in effect at the beginning of execution. This, combined with PERL_HASH_SEED and PERL_PERTURB_KEYS is intended to aid in debugging nondeterministic behaviour caused by hash randomization.

Note that any information about the hash function, especially the hash seed is sensitive information: by knowing it, one can craft a denial-of-service attack against Perl code, even remotely. Do not disclose the hash seed to people who don't need to know it. See also hash_seed() and key_traversal_mask() in Hash::Util.

An example output might be:

HASH_FUNCTION = ONE_AT_A_TIME_HARD HASH_SEED = 
0x652e9b9349a7a032 PERTURB_KEYS = 1 (RANDOM)
PERL_MEM_LOG
If your Perl was configured with -Accflags=-DPERL_MEM_LOG, setting the environment variable PERL_MEM_LOG enables logging debug messages. The value has the form <number>[m][s][t], where number is the file descriptor number you want to write to (2 is default), and the combination of letters specifies that you want information about (m)emory and/or (s)v, optionally with (t)imestamps. For example, PERL_MEM_LOG=1mst logs all information to stdout. You can write to other opened file descriptors in a variety of ways:

$ 3>foo3 PERL_MEM_LOG=3m perl ...
PERL_ROOT
(specific to the VMS port.) A translation-concealed rooted logical name that contains Perl and the logical device for the @INC path on VMS only. Other logical names that affect Perl on VMS include PERLSHRPERL_ENV_TABLES, and SYS$TIMEZONE_DIFFERENTIAL, but are optional and discussed further in perlvms and in README.vms in the Perl source distribution.
PERL_SIGNALS
Available in Perls 5.8.1 and later. If set to "unsafe", the pre-Perl-5.8.0 signal behaviour (which is immediate but unsafe) is restored. If set to safe, then safe (but deferred) signals are used.
PERL_UNICODE
Equivalent to the -C command-line switch. Note that this is not a boolean variable. Setting this to "1" is not the right way to "enable Unicode". You can use "0" to "disable Unicode", though (or alternatively unset PERL_UNICODE in your shell before starting Perl). See the description of the -C switch for more information.
SYS$LOGIN
(specific to the VMS port.) Used if chdir has no argument and HOME and LOGDIR are not set.

Perl and its various modules and components, including its test frameworks, may sometimes make use of certain other environment variables. Some of these are specific to a particular platform. Please consult the appropriate module documentation and any documentation for your platform for variables peculiar to those specific situations.

Perl makes all environment variables available to the program being executed, and passes these along to any child processes it starts. However, programs running setuid would do well to execute the following lines before doing anything else, just to keep people honest:

$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)};

查看英文版

查看中文版