I am having problems with the chomp command

Not true. You proved yourself it's not a problem with chomp by using s/// and still having the same problem. chomp only removes from the end of string, and only removes the string found in $/ ("\n" by default).

I suspect that your string might have characters your terminal interprets as control characters, causing some or all of the line to be overwritten. Specifically, the "a" is being overwritten by the following space:

print "DEBUG: After chomp: $summaryFile \n"; ^ |

The "a" wasn't being overwritten before the chomp because the newline was printing the space on a new line.

I suspect you actually get the following output:

DEBUG: Before chomp: /warp/pub/testbot2/users/rehmanz/2009Aug23_151934 +/essw/bats /autobats/summary.log DEBUG: After chomp: /warp/pub/testbot2/users/rehmanz/2009Aug23_151934/ +essw/bats/ utobats/summary.log

(Boooo! Saying it adds a space in the middle of the output is very inaccurate.)

This can be obtained on an 80-col terminal with the following input:

"/warp/pub/testbot2/users/rehmanz/2009Aug23_151934/essw/bats/autobats/ +summary.log\r\n"

Your file has DOS line endings, but you're not using the :crlf PerlIO layer. You should convert your file, but using the following should do the trick (and trims trailing whitespace as a bonus):

s/\s+\z//;

If that's not the case, check what your string actually is by piping the output through od -c.

Update: Added everything after "I suspect" except for the last paragraph.


In reply to Re: Problems with chomp by ikegami
in thread Problems with chomp by autotester747

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.