note
Thilosophy
In a language as dynamic as Perl, we cannot have a lot of compile-time checks, and I am always happy when it happens, as in this case. I commend the compiler for complaining!
<p><i>Obviously, it doesn't make much sense to chomp a constant, but if your operating within a sub, you don't know what the user will pass you.</i>
<p>I do not quite understand this. Inside of a sub, when the user passes in some data, it would not be a constant, would it?
<p><i>If the user passes a constant that doesn't need chomping it would be nice to allow that thtough without having to duplicate the tests inherent in chomp?</i>
<p>What exactly do you mean by constant? I take it to be something that is known at compile-time.
<p>I think it would be nice if the compiler optimized away the chomp completely if called with a compile-time constant. But I am not sure this is a feature many people need.
<p><b>Update:</b> After reading [id://BigLug]'s response and his excellent examples, I now understand what you meant by "inside of a sub". In this case, I tend to agree with you, that the run-time error that occurs when you pass in a read-only 'fred' (which does not need to be modified) is a little harsh. On the other hand, the subroutine <code>modify</code> wants to modify its parameter and passing constants to it would be as illegal as passing them directly to <code>chomp</code>.
438514
438514