If you're really bothered, make a temporary copy of the value, print using that, then free it

Yes, that's pretty much my goto approach when I have a sub that can potentially alter the flags of its arguments && I want to avoid doing so.
In some cases it can be a bit tedious, and I've often wondered whether it's feasible to instead just allow the flag alteration(s) to occur and then revert it/them. (Hence my question.)

For the demo case I provided, just calling SvPOK_off(sv); would be sufficient to restore the flags (as reported by Devel::Peek::Dump) to their original values. That would then have $sv Dump()ing to:
SV = PVIV(0x33fea8) at 0x33d0e0 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 12345 PV = 0x2838458 "12345"\0 CUR = 5 LEN = 10
If the objective is to simply keep those flags unchanged, then that objective has now been met. But are there any gotchas associated with leaving $sv in that state ?

I'm not really all that bothered about flags being changed - except for when it happens without good reason.
As an example of flags being changed for no good reason, consider:
> perl -MStorable -MDevel::Peek -le "$v = 2**70; Dump($v); $f = Stora +ble::freeze(\$v); Dump($v)" SV = NV(0x47e370) at 0x47e388 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 1.18059162071741e+21 SV = PVNV(0x30a3e8) at 0x47e388 REFCNT = 1 FLAGS = (NOK,pIOK,pNOK,IsUV) UV = 18446744073709551615 NV = 1.18059162071741e+21 PV = 0
I don't think we should assume that such an unannounced and unexpected alteration to the flags of $v would be of no consequence to the user.

Cheers,
Rob

In reply to Re^2: Reverting the internals of an IV to their original states by syphilis
in thread Reverting the internals of an IV to their original states by syphilis

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.