use Carp qw(croak);
sub instance_only {
ref(my $self = shift ) or croak "instance variable needed";
... use $self as the instance ...
}
sub class_only {
ref(my $self = shift) and croak "class name needed";
... use $class as the class..
}
instance variable needed at their_code line 1234
告诉用户引起问题的行号
croak->die
crap->warn
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24104518/viewspace-722725/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24104518/viewspace-722725/
本文介绍了一段Perl编程中的实用技巧,包括如何使用特定的Perl语法来处理实例变量和类变量的问题,以及如何通过croak函数优雅地处理错误。
1607

被折叠的 条评论
为什么被折叠?



