大佬教程收集整理的这篇文章主要介绍了perl – 为什么要使用警告?去最后?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我/ Warnings.pm
package My::Warnings; use warnings::register; sub test { warnings::warnif 'This is my warning'; } 1;@H_470_6@main.pl
use Strict; use feature 'switch'; use warnings 'all'; use My::Warnings; print undef; given (1) { } My::Warnings::test();
如预期的那样,这将产生
given is experimental at E:\Perl\source\main.pl line 10. Use of uninitialized value in print at E:\Perl\source\main.pl line 8. This is my warning at E:\Perl\source\main.pl line 12.
但是,如果任何警告类别被禁用,它也将禁用自定义类别.喜欢这个
use Strict; use feature 'switch'; use warnings 'all'; no warnings 'experimental'; use My::Warnings; print undef; given (1) { } My::Warnings::test();
这只输出
Use of uninitialized value in print at E:\Perl\source\main.pl line 9.
并且似乎有必要在使用My :: Warnings之后启用警告以使其执行
use Strict; use feature 'switch'; use My::Warnings; use warnings 'all'; no warnings 'experimental'; print undef; given (1) { } My::Warnings::test();
产生
Use of uninitialized value in print at E:\Perl\source\main.pl line 9. This is my warning at E:\Perl\source\main.pl line 13.
更新
此外,重新启用关闭自定义警告的类别会使其被禁用
这样的东西
use Strict; use feature 'switch'; use warnings 'all'; no warnings 'experimental'; use warnings 'experimental'; use My::Warnings; print undef; given (1) { } My::Warnings::test();
打印
given is experimental at E:\Perl\source\main.pl line 12. Use of uninitialized value in print at E:\Perl\source\main.pl line 10.
以上是大佬教程为你收集整理的perl – 为什么要使用警告?去最后?全部内容,希望文章能够帮你解决perl – 为什么要使用警告?去最后?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。