Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I take a reference to specific hash value in Perl?

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";
like image 676
dave Avatar asked Mar 25 '10 04:03

dave


1 Answers

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";
like image 120
muruga Avatar answered Oct 31 '22 18:10

muruga