Tud*_*tin 102 perl flags command-line
我已经看到了许多使用不同标志运行Perl代码或脚本的方法.但是,当我尝试google每个标志的含义时,我主要将结果发送到通用Perl网站,并且没有关于标志或其使用的具体信息.
以下是我经常遇到的旗帜,我不知道它们的含义:
如果你告诉我每个人的意思和一些用例,或者至少告诉我找出其含义的方法,我将非常感激.
pax*_*blo 141
是的,谷歌是用于查找标点符号非常困难的,不幸的是,Perl中也似乎主要是由标点符号的:-)
命令行开关都在perlrun中详细说明.(可通过调用从命令行获得perldoc perlrun)
简要介绍一下选项,一个接一个:
-p: Places a printing loop around your command so that it acts on each
line of standard input. Used mostly so Perl can beat the
pants off awk in terms of power AND simplicity :-)
-n: Places a non-printing loop around your command.
-e: Allows you to provide the program as an argument rather
than in a file. You don't want to have to create a script
file for every little Perl one-liner.
-i: Modifies your input file in-place (making a backup of the
original). Handy to modify files without the {copy,
delete-original, rename} process.
-w: Activates some warnings. Any good Perl coder will use this.
-d: Runs under the Perl debugger. For debugging your Perl code,
obviously.
-t: Treats certain "tainted" (dubious) code as warnings (proper
taint mode will error on this dubious code). Used to beef
up Perl security, especially when running code for other
users, such as setuid scripts or web stuff.
zel*_*lio 10
该-p标志基本上运行脚本
while (<>) {
# exec here
}
continue {
print or die "-p destination: $!\n";
}
Run Code Online (Sandbox Code Playgroud)
-e 允许您传递脚本 STDIN
perl -e '$x = "Hello world!\n"; print $x;'
Run Code Online (Sandbox Code Playgroud)
-i指示解释器STDIN执行脚本传递给的所有数据都将在原地完成.
-w是相同的use warnings;,但是在全球而不是局部范围内
-d 运行Perl调试器
小智 8
其他人提到了perlrun.如果你使用B :: Deparse,你可以看到它意味着什么(对于大多数事情):
$ perl -MO=Deparse -p -e 1
LINE: while (defined($_ = <ARGV>)) {
'???';
}
continue {
die "-p destination: $!\n" unless print $_;
}
-e syntax OK
Run Code Online (Sandbox Code Playgroud)
1由'???'表示,因为它被优化掉了.
$ perl -MO=Deparse -p -i -e 1
BEGIN { $^I = ""; }
LINE: while (defined($_ = <ARGV>)) {
'???';
}
continue {
die "-p destination: $!\n" unless print $_;
}
-e syntax OK
Run Code Online (Sandbox Code Playgroud)
-i设置$ ^ I,就像
$ perl -MO=Deparse -p -i.bak -e 1
BEGIN { $^I = ".bak"; }
LINE: while (defined($_ = <ARGV>)) {
'???';
}
continue {
die "-p destination: $!\n" unless print $_;
}
-e syntax OK
Run Code Online (Sandbox Code Playgroud)
但请记住,<ARGV>使用2参数打开,因此没有以> </或开头/结尾的文件名|.
还有一个重要的标志-n没有在列表中提到。
-n与 相同-p,只是$_默认情况下不打印。这在过滤文本文件时非常有用。
通过这种方式,Perl 可以grep | sed在单个单行中替换。
例如:
perl -ne 'print "$1\n" if /Messages read: (\d+)/' <my_input.txt
将打印出在“消息读取:”之后找到的每个整数值,仅此而已。
| 归档时间: |
|
| 查看次数: |
61222 次 |
| 最近记录: |