Groxx has asked for the wisdom of the Perl Monks concerning the following question:
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).#!/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";
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."
|
---|