And for lexical variables, you can use the Lexical::Alias module:

$ perl use Lexical::Alias 'alias_r'; my $s; alias_r \"I am immutable", \$s; $s = "fie!"; ^D Modification of a read-only value attempted at - line 6. $

Update: I don't think it's documented behaviour. It just happens to work, probably because of the way the module is implemented (I am by no means a perlguts expert - and I haven't studied the source). Here's a snippet from the module documentation:

alias_r(\src, \dst)

Makes dst (which must be lexical) an alias to src (which can be either lexical or a package variable). src and dst must be the same data type (scalar and scalar, array and array, hash and hash). This is not exported by default.

Of course you can play by the rules:

[...] my $s; { local $tmp; *tmp=\"I am immutable"; alias_r \$tmp, \$s; } [...]

In reply to Re: Re: There is a way to LOCK a SCALAR? by calin
in thread There is a way to LOCK a SCALAR? by gmpassos

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.