This code:
#!/usr/bin/perl # removenewlines use warnings; #use strict; $/ = undef; open IN, shift or die "Failed at opening given file: $!"; $InFile = <IN>; $Output = $InFile; $Output =~ s/\n/things/g; print $Output . "\n";
is behaving oddly, and I'm not sure what the reason is. When it finds a newline character in my CSV file, it not only removes the newline and replaces it with "things", as it should, but it also includes a fair amount of the line of text before it (the amount varies, and it doesn't seem to follow any logic. Sometimes it removes text starting in the middle of a word, sometimes after another character, though in the file I have it's always removing the same amount each time. It seems to only remove less than 100 characters each time (though I've only tested it with a fairly small file).
I know about a few CSV modules, but they aren't serving my needs (ie, they aren't capturing the data correctly 100% of the time), so I'm building what I need as I need it. The main snag has been that one of the CSV files can contain newline characters within a field, so I started making code to replace them. It wasn't working, so I made this to test the behavior... and now I'm stumped.
Below are two of the fields before and after:

An example of a "normal" CSV line (they all have quoted areas):

"inkjet001","Inkjet Printer",4,"prodimages/inkjetprinter.gif","prodima +ges/linkjetprinter.gif",95,90,130,4,0,2.02,1,1,0,0,"",,0,0,0,"This in +kjet printer really packs a punch for the home user. Full color print +s at photo quality. Perfect for everything from letters to the bank m +anager, to printing out your favourite digital family pictures.","Thi +s inkjet printer really packs a punch for the home user. Full color p +rints at photo quality. Perfect for everything from letters to the ba +nk manager, to printing out your favourite digital family pictures.<b +r>As well as a larger image, you can use this ""Long Description"" to + add extra detail or information about your products."
"inkjet001","Inkjet Printer",4,"prodimages/inkjetprinter.gif","prodima +ges/linkjetprinter.gif",95,90,130,4,0,2.02,1,1,0,0,"",,0,0,0,"This in +kjet printer really packs a punch for the home user. Full color print +s at photo quality. Perfect for everything from letters to the bank m +anager, to printing out your favourite digital family pictures.","Thi +s inkjet printer really packs a punch for the home user. Full color p +rints at photo quality. Perfect for everything from letters to the ba +nk manager, to printing out your favourite digital family pictures.<b +r>As well as a larger image, you can use this ""Long Descthings

An example of a "line" with a newline:

"testproduct","Cheap Test Product",3,"prodimages/computercable.gif","p +rodimages/lcomputercable.gif",0.01,0.01,0,0,0,3,1,1,0,0,"",,0,0,0,"Th +is is a cheap product for testing. Note how you can use <b>HTML <font + color='#FF0000'>Markup</font></b> in product descriptions.<br>Also n +ote that as you change the product options, the price changes automat +ically.","This is a cheap product for testing. Note how you can use < +b>HTML <font color='#FF0000'>Markup</font></b> in product description +s.<br> In the long description you can go into more detail about products."
"testproduct","Cheap Test Product",3,"prodimages/computercable.gif","p +rodimages/lcomputercable.gif",0.01,0.01,0,0,0,3,1,1,0,0,"",,0,0,0,"Th +is is a cheap product for testing. Note how you can use <b>HTML <font + color='#FF0000'>Markup</font></b> in product descriptions.<br>Also n +ote that as you change the product options, the price changes automat +ically.","This is a cheap product for testing. Note how you can use < +b>HTML <font color=thingsIn the long description you can go into more + detail about products."

In reply to newline substitution is removing text too by Groxx

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.