是否可以在Perl中启用/禁用基于ARGV的使用严格/警告?
发布时间:2020-12-16 06:07:15 所属栏目:大数据 来源:网络整理
导读:是否可以在Perl中启用/禁用基于ARGV的使用严格/警告? 我尝试了这段代码,但它不起作用.我认为它应该在’$x = 2’的行中产生警告错误; # Do this at the beginning of the script BEGIN { if ( $ARGV[0] =~ /^Y$/i ) { use strict; use warnings; } else { no
是否可以在Perl中启用/禁用基于ARGV的使用严格/警告?
我尝试了这段代码,但它不起作用.我认为它应该在’$x = 2’的行中产生警告错误; # Do this at the beginning of the script BEGIN { if ( $ARGV[0] =~ /^Y$/i ) { use strict; use warnings; } else { no strict; no warnings; } } $x = 2; print "x is $xn"; 目的是仅在开发中启用警告消息. 解决方法use strict; 相当于 BEGIN { require strict; import strict; } 所以使用严格的效果;是无条件的(因为import strict;在if之前评估). 此外,使用严格和使用警告的效果都是词法范围的,因此它们的效果仅限于它们一如既往的位置. 使用 no strict; # Probably not actually needed. no warnings; # Probably not actually needed. use if scalar( $ARGV[0] =~ /^Yz/i ),'strict'; use if scalar( $ARGV[0] =~ /^Yz/i ),'warnings'; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |