Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: A Scalar::Util::refaddr Oddity

by ambrus (Abbot)
on Sep 25, 2005 at 20:24 UTC ( [id://494956]=note: print w/replies, xml ) Need Help??


in reply to A Scalar::Util::refaddr Oddity

Are there any odd side effects of that blessing?

I think yes.

Firstly, if someone uses the string value of an unblessed reference as a hash key (for example for memoizing some function of the reference), then calling refaddr on this reference would change the string and thus make the program fail. That's a bad practice anyway, as string values of scalar references can change even without reblessing, as the prefix can be SCALAR, REF, GLOB etc. You should use the numeric values of references instead. However, some code can still use it, do I'd consider this an odd side effect.

Secondly, doesn't this function blow up on a reference to a constant, such as $x = \5; $ad = refaddr($x);? It still makes sense to take the address of such a reference.

Replies are listed 'Best First'.
Re^2: A Scalar::Util::refaddr Oddity
by Zaxo (Archbishop) on Sep 25, 2005 at 20:31 UTC

    On blowup, it sure does, with "Modification of constant" error. Thanks, I hadn't noticed that one.

    After Compline,
    Zaxo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found