gpt4 book ai didi

perl - 为什么我不能说 print $somehash{$var}{fh} "foo"?

转载 作者:行者123 更新时间:2023-12-04 04:44:58 25 4
gpt4 key购买 nike

我有一行代码:

print $somehash{$var}{fh} "foo";

哈希包含向下几级的文件句柄。错误是:
String found where operator expected at test.pl line 10, near "} "foo""

我可以通过这样做来解决它:
my $fh = $somehash{$var}{fh};
print $fh "foo";

...但是有单行吗?

最佳答案

http://perldoc.perl.org/functions/print.html

Note that if you're storing FILEHANDLEs in an array, or if you're using any other expression more complex than a scalar variable to retrieve it, you will have to use a block returning the filehandle value instead: ...



因此,在您的情况下,您将使用这样的 block :
print { $somehash{$var}{fh} } "foo";

关于perl - 为什么我不能说 print $somehash{$var}{fh} "foo"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/544088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com