我应该使用命令行开关或编译指示打开Perl警告吗? [英] Should I turn on Perl warnings with the command-line switch or pragma?

查看:70
本文介绍了我应该使用命令行开关或编译指示打开Perl警告吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面两个示例之间在开始Perl脚本方面有区别吗?如果是这样,我什么时候可以使用另一个?

Is there a difference between the two examples below for beginning a Perl script? If so, when would I use one over the other?

示例1:

#!/usr/bin/perl

use warnings;

示例2:

#!/usr/bin/perl -w

推荐答案

使用该开关将在程序使用的 all 模块中启用所有警告.使用编译指示,只能在该特定模块(或脚本)中启用它.理想情况下,您在所有模块中都使用警告,但通常并非如此.当您使用不是警告安全的第三方模块时,使用该开关会收到很多警告.

Using the switch will enable all warnings in all modules used by your program. Using the pragma you enable it only in that specific module (or script). Ideally, you use warnings in all your modules, but often that's not the case. Using the switch can get you a lot of warnings when you use a third party module that isn't warnings-safe.

因此,理想情况下这并不重要,但从实用上讲,对于最终用户而言,通常最好不要使用开关,而要使用编译指示.

So, ideally it doesn't matter, but pragmatically it's often preferable for your end-users not to use the switch but the pragma.

这篇关于我应该使用命令行开关或编译指示打开Perl警告吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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