人们总是给我举鲤鱼的例子,而不是警告我。为什么?是什么让鲤鱼比警告更好?
carp 为您提供有关消息来源的更多信息(上下文)
#!/usr/bin/perl
use Carp;
foo();
bar();
baz();
sub foo {
warn "foo";
}
sub bar {
carp "bar";
}
sub baz {
foo();
bar();
}
produces
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
对于这个小程序来说有点傻,但是当你想知道谁调用了吹毛求疵的方法时就派上用场了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)