我读到use warnings;
更好而不是放置 -w
在shebang结束时。
两者有什么区别?
最佳答案
The warnings pragma is a replacement for the command line flag -w, but the pragma is limited to the enclosing block, while the flag is global. See perllexwarn for more information and the list of built-in warning categories.
use warnings
的优势|是它可以关闭,并且只影响直接范围。例如,考虑一个使用会发出警告的操作的模块:
package Idiotic;
sub stuff {
1 + undef;
}
如果我们这样做,我们会收到警告
#!perl -w
use Idiotic; # oops, -w is global
Idiotic::stuff();
但不要收到任何警告
#!perl
use warnings; # pragmas are scoped, yay!
use Idiotic;
Idiotic::stuff();
关于perl - “使用警告”与 '#!/usr/bin/perl -w' 有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23299556/