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:

--- sv.c.org 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:

--- sv.c.org 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


In reply to Re: How to prevent references from stringifying? by xmath
in thread How to prevent references from stringifying? by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.