perl shebang:`“-Mstrict”为时已晚`
perl shebang: `Too late for "-Mstrict" `
我有以下可敬的 perl 脚本 x.pl
:
#!/usr/bin/env -S perl -Mstrict -wp
s/a/b/;
如果我用 ./x.pl
或 perl x.pl
运行 它,它会用
爆炸
Too late for "-Mstrict" option at ./x.pl line 1.
但是……为什么?我认为“为时已晚......”只是 -CSDA
或 -T
之类的问题,因为“流已经打开”。此外,shebang 行实际上不是简单地使用指定的开关调用 perl 吗?
-M
和 -m
开关不适用于 Perl 脚本。
#!/usr/bin/perl -Mstrict
# shebang.pl
print 42;
$ perl -Mdiagnostics shebang.pl
Too late for "-Mstrict" option at - line 1 (#1)
(X) The #! line (or local equivalent) in a Perl script contains the
-M, -m or -C option.
In the case of -M and -m, this is an error because those options
are not intended for use inside scripts. Use the use pragma instead.
The -C option only works if it is specified on the command line as
well (with the same sequence of letters or numbers following). Either
specify this option on the command line, or, if your system supports
it, make your script executable and run it directly instead of passing
it to perl.
Uncaught exception from user code:
Too late for "-Mstrict" option at - line 1.
这是一个有意的警告,而不是加载失败。他们想阻止您尝试在 shebang 线上加载模块,即使它(有时)确实有效。这是因为 Perl 无法保证 OS 如何解析和执行脚本的 shebang 行。所以这只是被禁止的。阅读 perlrun
了解更多信息。 Perl 在启动后实际上重新解析 shebang 行以检查在执行时未正确传递的选项。
$ cat script.pl
#!/usr/bin/perl -w -Mthing
print "Hello world\n";
$ cat thing.pm
package thing;
$|=1;
print "thing was loaded\n";
sub import { print "thing import was imported\n"; }
$ ./script.pl
thing was loaded
thing import was imported
Too late for "-Mthing" option at ./script.pl line 1.
$ perl ./script.pl
Too late for "-Mthing" option at ./script.pl line 1.
$ perl -x ./script.pl
thing was loaded
thing import was imported
Hello world
我同意它现在有点过时,但它是一种将 OS 执行与程序分开的方法。
我有以下可敬的 perl 脚本 x.pl
:
#!/usr/bin/env -S perl -Mstrict -wp
s/a/b/;
如果我用 ./x.pl
或 perl x.pl
运行 它,它会用
Too late for "-Mstrict" option at ./x.pl line 1.
但是……为什么?我认为“为时已晚......”只是 -CSDA
或 -T
之类的问题,因为“流已经打开”。此外,shebang 行实际上不是简单地使用指定的开关调用 perl 吗?
-M
和 -m
开关不适用于 Perl 脚本。
#!/usr/bin/perl -Mstrict
# shebang.pl
print 42;
$ perl -Mdiagnostics shebang.pl
Too late for "-Mstrict" option at - line 1 (#1) (X) The #! line (or local equivalent) in a Perl script contains the -M, -m or -C option.
In the case of -M and -m, this is an error because those options are not intended for use inside scripts. Use the use pragma instead.
The -C option only works if it is specified on the command line as well (with the same sequence of letters or numbers following). Either specify this option on the command line, or, if your system supports it, make your script executable and run it directly instead of passing it to perl.
Uncaught exception from user code: Too late for "-Mstrict" option at - line 1.
这是一个有意的警告,而不是加载失败。他们想阻止您尝试在 shebang 线上加载模块,即使它(有时)确实有效。这是因为 Perl 无法保证 OS 如何解析和执行脚本的 shebang 行。所以这只是被禁止的。阅读 perlrun
了解更多信息。 Perl 在启动后实际上重新解析 shebang 行以检查在执行时未正确传递的选项。
$ cat script.pl #!/usr/bin/perl -w -Mthing print "Hello world\n"; $ cat thing.pm package thing; $|=1; print "thing was loaded\n"; sub import { print "thing import was imported\n"; } $ ./script.pl thing was loaded thing import was imported Too late for "-Mthing" option at ./script.pl line 1. $ perl ./script.pl Too late for "-Mthing" option at ./script.pl line 1. $ perl -x ./script.pl thing was loaded thing import was imported Hello world
我同意它现在有点过时,但它是一种将 OS 执行与程序分开的方法。