这是重现问题的代码:
sub hello { return (h => 1, n => 1); } print join ", ", values hello();我收到错误:
arg 1 to values 的类型必须是 hash(不是子程序入口)在 - 第 4 行,靠近 ");"执行 - 中止到期编译错误.
Type of arg 1 to values must be hash (not subroutine entry) at - line 4, near ");" Execution of - aborted due to compilation errors.
我知道我可以中断通话并打印两行:
I know I can break the call and the print on two lines:
sub hello { return (h => 1, n => 1); } my %hash = hello(); print join ", ", values %hash;但我不想那样做.有没有办法在一行中做到这一点,这样我就不必一直创建临时变量?
But I don't want to do that. Is there some way to do this in one line so that I don't have to create temporary variables all the time?
推荐答案我没有看到在实际程序中的用处,但是是的,这是可能的.
I don't see the usefulness in a real program, but yes, it is possible.
print join ", ", values %{{hello()}};说明:hello() 是一个列表;{hello()} 是一个哈希引用;%{{hello()}} 是一个哈希值.
Explanation: hello() is a list; {hello()} is a hash reference; %{{hello()}} is a hash.
更多推荐
在函数调用的同一行获取哈希键/值
发布评论