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

Re: How to prevent references from stringifying?

by xmath (Hermit)
on Oct 03, 2004 at 14:57 UTC ( #396016=note: print w/replies, xml ) Need Help??

in reply to How to prevent references from stringifying?

I just checked the perl source. I don't see any way of doing this for general references without patching perl. The good news is that's it's easy to patch, so if you're comfortable with recompiling your perl to debug your problem, it's an option.

For perl 5.8.5:

--- 2004-07-12 23:44:41.000000000 +0200 +++ sv.c 2004-10-03 16:54:08.000000000 +0200 @@ -3126,2 +3126,3 @@ } + Perl_croak(aTHX_ "Stringification of reference disallowed"); tsv = NEWSV(0,0);

This still allows stringification of compiled regexen, or when overloading is in place. If you want to disallow stringification in those cases too (so, for all references), you can instead do:

--- 2004-07-12 23:44:41.000000000 +0200 +++ sv.c 2004-10-03 16:56:34.000000000 +0200 @@ -3001,2 +3001,3 @@ SV* tmpstr; + Perl_croak(aTHX_ "Stringification of reference disallowed"); if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,string)) &&

UPDATE: Just in case you're unfamiliar with applying a patch: unpack the perl 5.8.5 source, save one of the above snippets as "patchfile", execute (in the unpacked perl dir) the following command: patch < path/to/patchfile and then compile perl normally

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://396016]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2018-06-22 10:28 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.