It would seem to me (and I don't know the history) but this is probably the best reason I've seen why chomp returns what it does instead of the modified string. This way you can test its return and decide if worked as expected or if it is an error. Assuming that we all have your same need and care if there was a line ending is ridiculous. By your logic if i wanted to only remove the line ending i would have to first check if it had an ending and then only precede to remove it if needed. It seems like you are putting the burden then on the normal case instead of on your special case. I've worked with many data files and formats and not having to care about the line endings is a blessing not a curse. In addition if your are counting on the presence of a line ending to signify a valid record instead of checking the actual structure of the record i would think you are going to have more trouble, not less, in the future.


___________
Eric Hodges

In reply to Re: chop vs chomp by eric256
in thread chop vs chomp by Moron

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.