I stumbled over the fact that literal references are not readonly.
Is that a bug or am I missing an obscure reason for this???
DB<18> use Scalar::Util qw/readonly/
DB<19> p readonly 1
34283264
DB<20> p readonly undef
34283264
DB<21> p readonly {} # What?
DB<22> p readonly [] # ...
DB<23> p readonly bless([],"TEST") # ...
DB<24> x [],{},bless([],"TEST") # all refs
ARRAY(0x334ebd0)
empty array
HASH(0x334ec00)
empty hash
TEST=ARRAY(0x334eb70)
empty array
DB<25> x map { $_ = 1 } [],{},bless([],"TEST") # mutable! WHY???
1
1
1
DB<26>
update
counter-examples
DB<32> x map { $_ = 1 } "str"
Modification of a read-only value attempted at (eval 42)[c:/Perl_524/l
+ib/perl5db.pl:737] line 2.
DB<33> x map { $_ = 1 } 42
Modification of a read-only value attempted at (eval 43)[c:/Perl_524/l
+ib/perl5db.pl:737] line 2.
DB<34> x map { $_ = 1 } undef
Modification of a read-only value attempted at (eval 44)[c:/Perl_524/l
+ib/perl5db.pl:737] line 2.
update
see also Re^10: Shouldn't references be readonly? (UPDATED) for another example of the asymmetric behavior.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|