in reply to Changing a returned hashref

The problem is this piece of code:

sub two{ $_[0]->{HASH} = {1 => 'one'}; }

It doesn't modify the hash that $_[0]{HASH} points to, but rather stores a new reference in there. Modifying the existing hash works:

sub two{ $_[0]->{HASH}{1} = 'one'; }

Replies are listed 'Best First'.
Re^2: Changing a returned hashref
by cqd (Initiate) on Nov 09, 2011 at 10:14 UTC
    Wow! Thanks for the fast reply! It works like a charm!

    I changed the password while being logged in so the question was unfortunately assigned to an anonymous monk, hehe.

Re^2: Changing a returned hashref
by cqd (Initiate) on Nov 09, 2011 at 12:23 UTC

    Just to clarify for myself, I experimented a little and found that this clarified things a bit for me:

    ${$self->{HASH}}{1} = 'one';
        Thanks!

        What I found a bit confusing was how perl see the above hashref as a reference to another hashref instead of a reference to a hash with 2 keys...