Perl:如何检查子例程返回的内容
我有一个子例程,当一切顺利时,它将返回两个哈希值。但是子检查命令的输出,如果它匹配某个模式,它将返回“-1”。无论如何,有没有办法从我调用它的地方检查子例程的返回?
有点像:
if (RETURN_VALUE == -1){
do something}
else
go as normal with the hashes
I have a subroutine that will return two hashes when all goes well. But the sub checkouts output of command and if it matches a certain pattern, it returns with "-1". Is there anyway to check the return of the subroutine from where I called it?
Kinda like:
if (RETURN_VALUE == -1){
do something}
else
go as normal with the hashes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个函数如何返回两个哈希值?
如果您指的是
hashrefs
,那么检查将非常简单:How could one function return two hashes?
If you mean
hashrefs
, the check would be quite simple:您的函数应该在成功时返回对两个哈希值的引用,在失败时不返回任何内容。然后你可以检查函数调用的真值。
You function should return references to the two hashes on success and nothing upon failure. Then you can just check the truth value of the function call.
如果您从子例程返回两个(或任何数字)散列,则结果将是单个散列。您将无法以正常方式将原始哈希值与结果分开。返回哈希引用不会出现此问题。
假设 foo() 在模式匹配时返回两个哈希引用,在不匹配时返回 -1。
If you return two (or any number for that matter) hashes from a subroutine, the result will be a single hash. You will not be able to separate the original hashes from the result in a normal manner. Returning hash references will not exhibit this problem.
Suppose
foo()
returns two hash references when the pattern is matched and returns -1 when it does not match.