[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';
To be able to simplify a question adequately you need to have some idea
of what the answer is going to be. Clearly your expectation is
erroneous. Describe in English what data you want to store without
reference to Perl and we will help.
The value relating to a particular key stored in a hash is a scalar
value. That value can be a simple integer or string, or a reference to a
subsidiary hash or array.
If the value 1 in your code above is meaningless and is simply there so
that you can create the hash element then you can fix things by saying
$hash{'key'} = undef;
which will enable Perl to autovivify the subsidiary hash when you make
the second assignment.
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/