in reply to Modifying hash keys via aliasing

Hash keys are strings, not full-blown scalars. This is also why you can't have a hash key that is a reference.

You can't alias a string like you can alias a scalar. You could make a magic scalar that modifies a string when the scalar is modified, but that still wouldn't be enough, because then the string would be changed but the wrong bucket of the hash would be used. So changing a key really requires deleteing and then re-inserting. So Perl could create a magic scalar that does all that work but that would be pretty darn wasteful for the 99.9836% of cases when people do not try to modify hash keys via aliasing the return values from %h. So Perl doesn't do that.

(Yes, I read all of the other answers; I like this explanation better.)

- tye        

  • Comment on Re: Modifying hash keys via aliasing (strings)

Replies are listed 'Best First'.
Re^2: Modifying hash keys via aliasing (strings)
by vsespb (Chaplain) on Aug 11, 2015 at 08:32 UTC
    Thanks!