已经使用strict时是否需要使用警告? [英] Is it necessary to use warnings when already use strict?

查看:85
本文介绍了已经使用strict时是否需要使用警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

use strict;
use warnings;

此处是否需要使用警告;?

推荐答案

是的,这是必要的.

use strictuse warnings 做不同的事情.

use strict and use warnings do different things.

来自 strict 模块的手册页:

From the strict module's manpage:

strict - 限制不安全结构的 Perl 编译指示

strict − Perl pragma to restrict unsafe constructs

来自 perlrun(对于 -w):

打印关于可疑的警告构造,例如变量名只提到一次的标量变量用过的在设置之前,重新定义子程序,引用不明确的文件句柄或文件句柄以只读方式打开尝试写入,用作数字的值不看像数字一样,使用数组就好像它是标量一样,如果你的子程序递归超过 100 个深度,以及无数其他东西.

prints warnings about dubious constructs, such as variable names that are mentioned only once and scalar variables that are used before being set, redefined subroutines, references to undefined filehandles or filehandles opened read-only that you are attempting to write on, values used as a number that don't look like numbers, using an array as though it were a scalar, if your subroutines recurse more than 100 deep, and innumerable other things.

这篇关于已经使用strict时是否需要使用警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆