$ 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |