[EMAIL PROTECTED] wrote:
On Jan 15, 10:57 am, [EMAIL PROTECTED] (Gunnar Hjalmarsson) wrote:
[EMAIL PROTECTED] wrote:
How do I change the value stored to a hash reference?
C:\home>type test.pl
my %hash = (
     key => {
         refkey => 'oldvalue',
     },
);
print "$hash{key}->{refkey}\n";
$hash{key}->{refkey} = 'newvalue';
print "$hash{key}->{refkey}\n";

C:\home>test.pl
oldvalue
newvalue

C:\home>

I know how to change the value stored in hash, that isn't the
problem.  Here's a short example of the problem which fails...

use strict;

my %hash;
$hash{ 'key' } = 1;

$hash{ key }{ 'hoh' } = 'test';

It fails because the value of $hash{key} is not a hash reference. You still haven't properly explained what it is you want to accomplish... If you actually want to *replace* the value of $hash{key} with a hash reference, you can do:

    $hash{key} = { refkey => 'test' };

To study the resulting data structure, do:

    use Data::Dumper;
    print Dumper \%hash;

And to just print the value of the anonymous hash, do:

    print "$hash{key}->{refkey}\n";

HTH

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to