Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

chomp is based on chop and chop modifies in place so that it can return the character that was chopped, so it makes some sense to have chomp also modify in place since it just a "safer chop". chomp can also work on a list of items, in which case the return value is more than a Boolean.

Also, shortening a string in place is extremely efficient. To return a modified value would require allocating another buffer and copying nearly the entire string.

There are several operations that modify in place: s///, tr///, read(), sysread(), etc. For most of them, I've run into cases where I'd rather have them return the modified value so I do see your point. But the inconvenience is fairly minor -- we just get used to not having to up with even minor inconvenience because we are using Perl. (:

Also, if it only returned the modified value (and didn't also modify in place), then you'd constantly be writing $input_line= chomp($input_line) and requiring the repetition isn't good. If it modified in place and returned the modified value, then there'd be no good way to tell if a modification took place.

So it's a mixed bag. :-}

        - tye (but my friends call me "Tye")

In reply to (tye)Re: How do you chomp your chomps? by tye
in thread How do you chomp your chomps? by kaatunut

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 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?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-18 03:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found