That would require anyone calling the sub to tie the constants--which makes no sense at all.

It just took me by surprise that chomp died when asked to inspect a variable that was readonly. The work-arounds are myriad:

  1. The XS version of Scalar::Util has a readonly function.
  2. I could also use the eval block technique to catch the death. (Which is how the pure Perl version of Scalar::Util::readonly() does it.)
  3. The Internals package has a IsWriteProtected() function.
  4. I could use Inline::C to use the svREADONLY macro.
  5. etc.

But, as chomp has to determine if there is anything to chomp, before attempting to modify it's argument, I just expected it to make that determination before checking for readonlyness. It doesn't do it that way, so I have to do extra tests or copies myself.

I've gotten spoiled by Perl's DWIMming things like negative offsets don't die, they work backwards from the end. Same with negative subscripts; ranges that produce no values; empty lists that act correctly regardless of the context etc.

On this occasion it didn't DWIM for me.


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.

In reply to Re^2: Should chomping a constant always raise an error? by BrowserUk
in thread Should chomping a constant always raise an error? by BrowserUk

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.