Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Shouldn't LITERAL references be readonly? (updated) by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2021-10-28 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (95 votes). Check out past polls.

    Notices?