How to use Perl Storable, changing a hash value

4.4k Views Asked by At

I'm no Perl expert, so this is probably an easy question.

I've been using Storable, and following this example to store a hash. First, I store the original hash.

use Storable qw(store retrieve freeze thaw dclone);
%color = ('Blue' => 1, 'Red' => 0.8, 'Black' => 0, 'White' => 1);
store(\%color, 'mycolors');

Then I retrieve it. (different script)

use Storable qw(store retrieve freeze thaw dclone);
$colref = retrieve('mycolors');
printf "Blue is still %lf\n", $colref->{'Blue'};

My question is how can I change one of the hash values? For example, do something like

$colref->{'Blue'} = 2;
store(\%color, 'mycolors');

in the second script.

1

There are 1 best solutions below

0
On BEST ANSWER

Needed to change

store(\%color, 'mycolors');

to

store($colref, 'mycolors');