本文介绍了我如何在Perl中引用特定的哈希值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建对特定散列键值的引用。我尝试了以下,但$$ foo是空的。任何帮助都非常感谢。

How do I create a reference to the value in a specific hash key. I tried the following but $$foo is empty. Any help is much appreciated.

$hash->{1} = "one";
$hash->{2} = "two";
$hash->{3} = "three";

$foo = \${$hash->{1}};
$hash->{1} = "ONE";

#I want "MONEY: ONE";
print "MONEY: $$foo\n";


推荐答案

use strict;
use warnings;
my $hash;

$hash->{1} = "one";
$hash->{2} = "two";
$hash->{3} = "three";

my $foo = \$hash->{1};
$hash->{1} = "ONE";
print "MONEY: $$foo\n";

这篇关于我如何在Perl中引用特定的哈希值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 17:43
查看更多