How to update a hash value using a hash reference in Perl? -


is there way update value in hash using hash reference points hash value?

my hash output looks this:

    'alternate' => {         'free' => '27.52',         'primary' => 'false',         'used' => '0.01',         'name' => '/mydir/journal2',         'size' => '50.00'      },     'primary' => {         'free' => '60.57',         'primary' => 'true',         'used' => '0.06',         'name' => '/mydir/journal',         'size' => '64.00'     } }; 

i attempted create hash reference 'used' property in hash , tried update value:

$hash_ref = \%hash->{"primary"}->{used}; $hash_ref = "99%"; print $$hash_ref, "\n"; 

this changes value of hash, "using hash reference deprecated @ line x". i'd know if i'm trying possible , i'm doing wrong.

thanks

 ... 'primary' => {     'free' => '60.57',     'primary' => 'true',     'used' => '0.06',     'name' => '/mydir/journal',     'size' => '64.00' }  ... 

try bypass deprecation problem doing this:

 ... $hash_ref = $hash{'primary'}; # if declared `%hash = ( .. );` # or $hash_ref = $hash->{'primary'}; if declared `$hash = { .. };` print $hash_ref->{used}; # prints 0.06 $hash_ref->{used} = '0.07'; # update print $href->{used}; # prints 0.07  ... 

perldsc, if wanna learn more.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -