这是从perl中的子例程返回错误消息的好方法吗?
sub some_subroutine{
# do something
$something = 14;
if(1 == 2){
$_ = "This should not be happening!";
return undef;
}
return $something;
}
my $ret=some_subroutine();
print "ERROR: $_" unless(defined $ret);
Run Code Online (Sandbox Code Playgroud)
代码运行正常(在并行世界中,在哪里1 == 2
),但使用$_
返回错误消息是一个好方法?我没有找到任何关于$_
此类用途的使用文档.
谢谢!
perl ×1