perl - “使用警告”与 '#!/usr/bin/perl -w' 有区别吗?

标签 perl

我读到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.

warnings documentation


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/

相关文章:

perl - NET::FTP 在 perl 中放置命令

regex - Perl - 使用正则表达式来匹配哈希键或值中的输入

perl - 从 perl 确定父 shell

multithreading - Perl 线程之间共享套接字对象

perl - 为什么 smartmatch 根据操作数的顺序返回不同的值?

windows - 如何从 Perl 创建然后使用长 Windows 路径?

perl - 如何从多个 Perl 进程使用同一个 SQLite3 数据库?

perl - 如何在perl中将word文档转换为pdf文件?

perl - 如何使用 AnyEvent::XMPP 获取聊天室中的用户 jabber Id?

perl - 如何在 Perl 中搜索多个文件中的字符串?