in reply to Re: String wraps after a replace operation
in thread String wraps after a replace operation

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.

  • Comment on Re^2: String wraps after a replace operation

Replies are listed 'Best First'.
Re^3: String wraps after a replace operation
by Jim (Curate) on Jan 06, 2014 at 00:30 UTC

    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