“使用警告"与“#!/usr/bin/perl -w"有区别吗? [英] 'use warnings' vs. '#!/usr/bin/perl -w' Is there a difference?
本文介绍了“使用警告"与“#!/usr/bin/perl -w"有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我读到最好使用警告;
而不是在shebang的末尾放置-w
.
I read that it is better to use warnings;
instead of placing a -w
at the end of the shebang.
两者有什么区别?
推荐答案
warnings pragma 是命令行标志 -w 的替代品,但 pragma 仅限于封闭块,而标志是全局的.有关详细信息和内置警告类别列表,请参阅 perllexwarn.
use warnings
的优点是可以关闭,并且只影响直接作用域.
The advantage of use warnings
is that it can be switched off, and only affects the immediate scope.
以使用会发出警告的操作的模块为例:
Consider for example a module that uses operations that would emit 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();
这篇关于“使用警告"与“#!/usr/bin/perl -w"有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文