Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^5: A Scalar::Util::refaddr Oddity

by hv (Prior)
on Sep 27, 2005 at 16:23 UTC ( [id://495439]=note: print w/replies, xml ) Need Help??


in reply to Re^4: A Scalar::Util::refaddr Oddity
in thread A Scalar::Util::refaddr Oddity

Your code introduces a bug not in the original, here:

overload::StrVal($_[0]) =~ /0x(\w+)/;

You use the same regexp as the original, but because you are no longer blessing into a known package the regexp may match the package name instead of the address. Indeed, a bug common enough to warrant the introduction of a new fatal error in perl-5.8 would give rise to exactly that situation:

zen% cat t0 package A; $x = bless {}; $y = bless [], $x; print "$y"; zen% /opt/perl-5.6.1/bin/perl -wl t0 A=HASH(0x811198c)=ARRAY(0x8111a94) zen% /opt/perl-5.8.0/bin/perl -wl t0 Attempt to bless into a reference at t0 line 1.

Admittedly it is harder to get an overloaded object inadvertently in the wrong class like this, but "0x" is not so unusual a sequence of characters that it is fair to assume it will never appear in a legitimate package name. In any case it is easy enough to fix, with either /.*0x(\w+)/ or /0x(\w+)\)\z/.

Hugo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found