Somnath Paul
Somnath Paul

Reputation: 190

Issue in hash modification

I am printing a hash [ print Dumper($myhash); ], it is as below :

$VAR1= {
  'context_verdict' => 'Failed',
  'logfile' => 'abc',
  'Block_000' => {
     'Element_0032' => {
         'e_verdict' => 'FAILED',
         'e_name' => 'Element_0032',
         'e_log' => 'This is really bad...',
         'e_ref' => 'Good'
     }
  }

Now I want to change the value of logfile from abc to def. how to achieve this ?

I wrote

$myhash{'$VAR1'}->{'logfile'}="def";

But it does not works!! It is still the "abc".

Upvotes: 0

Views: 74

Answers (3)

Futuregeek
Futuregeek

Reputation: 1980

Data::Dumper helps to analyse a huge hash and the values will be named $VAR in the output.

Answer to your question is:

You can set the value as

   $myhash->{'logfile'}="def";

Upvotes: 0

ikegami
ikegami

Reputation: 385764

First of all, always use use strict; use warnings;.

You want

$VAR1->{'logfile'} = "def";

If you obtained the dump using Dumper(\%myhash),

$myhash{'logfile'} = "def";

If you obtained the dump using Dumper($myhash),

$myhash->{'logfile'} = "def";

$myhash holds a reference to a hash, so you need to dereference it to access the hash. That's what -> is doing.

Upvotes: 4

Miguel Prz
Miguel Prz

Reputation: 13792

Try this one:

$myhash->{'logfile'}="def";

Data::Dumper names your variable as $VAR1, this is not an entry in your hash.

Upvotes: 7

Related Questions