in reply to Implicit Reference Assignment Surprisingly Doesn't Overwrite Prior Scalar

You're in need of some strictness.

What's going on in your last example is what's called a symbolic reference. $h is 'foo'. And so $h->{bar} resolves $h to 'foo', and looks up a hash named 'foo'. If you printed out "$foo{bar}", you'd get the same 1 as you're getting with "$$h{bar}".

And that confusion is why strict doesn't allow symbolic references. They were required at one time, but that was over twenty years ago, I think, so avoiding them is generally the right idea now, when there are other, better, ways to refer to other objects.

  • Comment on Re: Implicit Reference Assignment Surprisingly Doesn't Overwrite Prior Scalar
  • Download Code

Replies are listed 'Best First'.
Re^2: Implicit Reference Assignment Surprisingly Doesn't Overwrite Prior Scalar
by jabowery (Beadle) on May 05, 2014 at 05:50 UTC
    Thanks! I actually did program in Perl4 back then but did not recall that twist. (And, yes, I did add 'use strict' after this happened.)