【发布时间】:2021-08-08 01:49:22
【问题描述】:
考虑这个简单的 perl 程序:
#!/usr/bin/perl -s
print "ARGV: @ARGV\n";
print "arg: $arg\n";
现在运行它:
chmod u+x test.pl
./test.pl -arg=works
输出是:
ARGV:
arg: works
在调试器中运行程序也可以:
perl -d test.pl -arg=works
Loading DB routines from perl5db.pl version 1.53
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(./test.pl:3): print $arg, "\n";
DB<1> c
ARGV: <-- SEE HERE
arg: works <-- SEE HERE
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
DB<1> q
但是,如果添加了包含路径,则将不再解析该参数:
perl -I . -d test.pl -arg works
Loading DB routines from perl5db.pl version 1.53
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(./test.pl:3): print $arg, "\n";
DB<1> c
ARGV: test.pl -arg=works <-- OOPS
arg: <-- OOPS
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
DB<1> q
当使用-I 时,@ARGV 的处理方式似乎不同。这就像-s 选项不再起作用,因为它应该使用像-opt=value 这样的开关。这是为什么呢?
Getopt::Long 和 Getopt::std 在所有情况下都可以正常工作。
我曾一度认为 Visual Studio Code 中的 Perl 扩展无法正常工作。
【问题讨论】:
-
我可以用
perl -I . -d test.pl -arg works复制这种行为,但不能用perl -I. -d test.pl -arg works复制(注意-I和它的参数之间没有空格)。奇数。
标签: perl