嗨,我对Perl很陌生。我有一个包含子例程的Perl哈希。我试图用我在网上找到的各种方式运行它。但似乎没有任何工作。 我的代码:不能在子程序的哈希里面激活子程序perl
%hashfun = (
start=>sub { print 'hello' },
end=>sub { print 'bye' }
);
而且我尝试了以下多。
print "\n $hashfun{start} \n";
这导致以下输出:
CODE(<十六进制值>)
然后我试图
print "\n $hashfun{start}->() \n";
这导致以下
CODE(<十六进制值>) - >()
如何解决?
您不能在字符串插值内运行coderef。 – simbabque
另请参阅['perlop'](http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators)中的*“Quote and Quote-Like Operators”*以获取有关在字符串内插入。 –
谢谢队友我会@HåkonHægland –