How can I replace a Perl hash key?

Viewed 19522

Let us say if I have a hash like this:

$data = {
    'key1' => {
                'key2' => 'value1'
              },
    'key3' => {
                'key4' => {
                            'key5' => 'value2'
                          }
              },
};

Now, how can I replace the the key 'key5' with some other key name, say 'key6'?

I know how to loop through the hash and dump the values, but I don't know how to replace keys or values in place.

3 Answers
Related