Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Implicit Reference Assignment Surprisingly Doesn't Overwrite Prior Scalar

by Tanktalus (Canon)
on May 05, 2014 at 04:20 UTC ( [id://1084994]=note: print w/replies, xml ) Need Help??


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.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1084994]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found