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:
-
Fix the problem with the source data and leave your code as it is.
-
Run the source data through some cleaning filter before you read it and leave your code as it is.
-
Edit your code to remove any bogus returns immediately after the chomp.
-
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.