Like others, I cannot reproduce your error with the code you've posted. Using Perl 5.14.2 and Mac OS X 10.7.4, I get:

BLA|001036|S|3228|10|1|2|3|001036|W035|S| |4 CHL|123777|S|3327|3|0|0|0|001036|W035|S| |2 BLT|600123|S|3437|0|20|0|0|001036|W035|S| |0 BRO|900177|S|3531|-1|0|0|0|001036|W035|S| |0

You asked "How do I get the count value to not print to a new line?". However, that's not really what's happening. Taking the first line of what you're getting, this actually looks like:

BLA|001036|S|3228|10|1|2|3|001036|W035|S|<space><some-return-char>|4<n +ewline>

The last pipe character comes from $"="|";; the 4 is your count value; the terminal <newline> is the \n from the print statement. The bogus <some-return-char> comes from the while loop's $_ value. I can reproduce your output by adding my own bogus return character:

... while( <DATA> ){ chomp; $_ .= qq{\n}; ...

which now outputs:

BLA|001036|S|3228|10|1|2|3|001036|W035|S| |4 CHL|123777|S|3327|3|0|0|0|001036|W035|S| |2 BLT|600123|S|3437|0|20|0|0|001036|W035|S| |0 BRO|900177|S|3531|-1|0|0|0|001036|W035|S| |0

You'll need to determine where the bogus return is added: it could be when the file is initially populated or perhaps due to some subsequent processing it undergoes before you read it. I've encountered this problem in the past when data is copied and pasted from an email, when data is transferred via FTP in binary mode and similar scenarios involving systems using different line endings.

I would suggest the following as your options:

  1. Fix the problem with the source data and leave your code as it is.
  2. Run the source data through some cleaning filter before you read it and leave your code as it is.
  3. Edit your code to remove any bogus returns immediately after the chomp.

-- Ken


In reply to Re: Need help with a simple perl script by kcott
in thread Need help with a simple perl script by quelos27

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.