in reply to Re: Should chomping a constant always raise an error?
in thread Should chomping a constant always raise an error?
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:
- The XS version of Scalar::Util has a readonly function.
- 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.)
- The Internals package has a IsWriteProtected() function.
- I could use Inline::C to use the svREADONLY macro.
- 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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Should chomping a constant always raise an error?
by Anonymous Monk on Mar 14, 2005 at 11:53 UTC | |
Re^3: Should chomping a constant always raise an error?
by ysth (Canon) on Mar 14, 2005 at 08:56 UTC | |
by BrowserUk (Patriarch) on Mar 14, 2005 at 09:02 UTC | |
by ysth (Canon) on Mar 14, 2005 at 09:11 UTC | |
by BrowserUk (Patriarch) on Mar 14, 2005 at 09:44 UTC | |
by ysth (Canon) on Mar 14, 2005 at 09:53 UTC |