Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

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

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 do not quite understand this. Inside of a sub, when the user passes in some data, it would not be a constant, would it?

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?

What exactly do you mean by constant? I take it to be something that is known at compile-time.

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.

Update: After reading 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 modify wants to modify its parameter and passing constants to it would be as illegal as passing them directly to chomp.


In reply to Re: chomping constants by Thilosophy
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":



  • 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 browsing the Monastery: (3)
As of 2022-06-27 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (88 votes). Check out past polls.

    Notices?