为什么我应该在Perl中使用Carp而不是警告?

前端之家收集整理的这篇文章主要介绍了为什么我应该在Perl中使用Carp而不是警告?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
人们继续给我鲤鱼的例子,而不是警告。为什么?什么使鲤鱼比警告更好?

解决方法

carp给你更多的信息,消息来自哪里(上下文) @H_404_6@#!/usr/bin/perl use Carp; foo(); bar(); baz(); sub foo { warn "foo"; } sub bar { carp "bar"; } sub baz { foo(); bar(); }

产生

@H_404_6@foo at ./foo.pl line 9. bar at ./foo.pl line 13 main::bar() called at ./foo.pl line 6 foo at ./foo.pl line 10. bar at ./foo.pl line 14 main::bar() called at ./foo.pl line 19 main::baz() called at ./foo.pl line 7

有点傻的这个小程序,但是当你想知道谁调用方法是鲤鱼的时候派上用场。

猜你在找的Perl相关文章