Thank you Jim and Toolic there is something in the $rt variable which is set according to a value in a hash of hashes. I will be able to troubleshoot tomorrow.
Regards
| [reply] |
Study this script, then run it.
use strict;
use warnings;
my $line = <DATA>;
my $rt = <DATA>;
my $cached_line = $line;
$line =~ s/Kept/Resold/g;
$line =~ s/,-1,/,$rt,/g;
print $line;
$line = $cached_line;
chomp $rt;
$line =~ s/Kept/Resold/g;
$line =~ s/,-1,/,$rt,/g;
print $line;
__DATA__
2013-06-13 19:00,2013-06-13,2013-06-01,212276,375296,-1,1461599,1434,6
+1073,US,Kept,300x250,1,0,0.25,0.00025
275805
This is what it prints.
2013-06-13 19:00,2013-06-13,2013-06-01,212276,375296,275805
,1461599,1434,61073,US,Resold,300x250,1,0,0.25,0.00025
2013-06-13 19:00,2013-06-13,2013-06-01,212276,375296,275805,1461599,1434,61073,US,Resold,300x250,1,0,0.25,0.00025
Does this help you understand the likely problem? As toolic suggested, the variable $rt probably has more in it than you think it does; namely, a trailing newline. If this is the problem, then the solution is to remove the newline using chomp.
Your problem likely has nothing to do with "wrapping," so forget about using Text::Wrap.
Jim
| [reply] [d/l] [select] |
My development environment is on cygwin, the issue was
due to my test text file containing sample data was
saved in a file Format = PC and encoding = DOS, once I changed it to Format = UNIX and encoding = ANSI my code worked.
| [reply] |
This is a classic: CR-LF versus LF newline differences in text files between operating systems (DOS/Windows versus Unix/Linux/OS X).
What text editor did you use to save the file using those formats and character encoding names? I ask this because those names are bogus and confusing, especially the character encoding names. There's no such thing as an encoding named "DOS", and the name "ANSI" is a historic misnomer that is more properly "Windows-1252" or "Code Page 1252" or "CP1252". I suspect the encoding name "DOS" is intended to mean "Code Page 437" or "CP437". But who knows?
You may need to use a better text editor.
Unless you're doing something extraordinary to thwart its default behavior (setting the mode of the I/O layer to :raw, for example), Perl should just be doing the right thing with the line terminators in your file. In other words, in general, Perl handles both CR-LF and LF logical newlines correctly and transparently. What version and distro of Perl are you using? ActiveState Perl? Strawberry Perl? Or the Perl that comes with Cygwin?
Jim
| [reply] [d/l] |