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":



  • 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.