This is sort of tricky because it just looks like it is working...First problem is that the \n is being kept, that's why ramlight's printout has an extra blank line in it. One way is to remove the \n is with chomp(). But there is another problem, because you only split on the "," character, the space before the 2nd token is being kept with it. I modified your print statement to show this:
print "\"$field1\"\t\"$field2\"\n"; output... I took out "" in data input because it was too confusing a printout. "-0.500" " 4.502e-6" "-0.499" " 4.474e-6" "-0.498" " 4.458e-6" "-0.497" " 4.445e-6" "-0.496" " 4.433e-6" "-0.495" " 4.421e-6"
One thing that could be done is split on any sequence of whitespace chars or the ",", like this:
my @fields = split /[\s,]+/;
That would handle extra "blank type" chars like \t. It also appears that you have "'s in input that you don't want. One way to get rid of them would be s/"//g; which just deletes them all.

I suspect that you will find some unprintable character as toolic suggests. Of course one way to deal with this is just modify the regex that gets rid of the " char to deal with any characters that we don't want to see: s/[^\w\.\,\-]//g;, that gets rid of anything not contained within this set which would include the ",\n chars also it possible to use "tr" for the same purpose. tr is a simple minded thing and as such it is faster than the s/// type operation. But fixing the input file is better as this "weirdness" can fester and propagate.

Finally, you can use array slice an get rid of the @fields intermediate variable. So some code with various possibilities...Hope some combination of ideas work for you.

while(<DATA>){ chomp(); #optional #s/[^\w\.\,\-]//g; tr /0-9.-e ,//dc; #another possibility.. my ($field1, $field2) = (split /[\s,]+/)[0,1]; print "\"$field1\"\t\"$field2\"\n"; } __DATA__ "-0.500, 4.502e-6" "-0.499, 4.474e-6" "-0.498, 4.458e-6" "-0.497, 4.445e-6" "-0.496, 4.433e-6" "-0.495, 4.421e-6"

In reply to Re: Invisible characters by Marshall
in thread Invisible characters by lomSpace

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.