Said mechanism is to make the SV readonly.
>perl -MDevel::Peek -e"Dump('Hello Sailor')" SV = PV(0x228e68) at 0x1831670 REFCNT = 1 FLAGS = (PADBUSY,PADTMP,POK,READONLY,pPOK) ^^^^^^^^ PV = 0x1833f3c "Hello Sailor"\0 CUR = 12 LEN = 16

Obviously that mechanism won't help you here.

In fact, a flag alone won't work since you'd need to know how many times a variable has been aliased to know when to remove the flag. (Upd: I'm not sure about the preceding statement. Can't think straight right now. )

You could add magic to the variable like taint does.

>perl -T -MDevel::Peek -e"Dump($ARGV[0])" foo SV = PVMG(0x1822dcc) at 0x226ba0 REFCNT = 1 FLAGS = (GMG,SMG,pPOK) IV = 0 NV = 0 PV = 0x182d324 "foo"\0 CUR = 3 LEN = 4 MAGIC = 0x182d33c MG_VIRTUAL = &PL_vtbl_taint MG_TYPE = PERL_MAGIC_taint(t) MG_LEN = 1

But now you're getting into costly.


In reply to Re^8: Changing array by changing $_? by ikegami
in thread Changing array by changing $_? by johnvandam

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.