How to substitute (regex) single newline (0A) character on Win32

M

msciwoj

Does anyone have an idea how to do output single \n (0A) character
instead of \r\n (0D0A) in win32?
Let's say I do replacement:
s/newlinemarker/\n/mg
and want to substitute single character 0A
Windows implementation seems to always be smarter and uses 0D0A
automatically... How to prevent it?
I tried:
\n
\r
\x0a
\cJ
....nothing worked so far...
 
S

Steve C

msciwoj said:
Does anyone have an idea how to do output single \n (0A) character
instead of \r\n (0D0A) in win32?
Let's say I do replacement:
s/newlinemarker/\n/mg
and want to substitute single character 0A
Windows implementation seems to always be smarter and uses 0D0A
automatically... How to prevent it?
I tried:
\n
\r
\x0a
\cJ
...nothing worked so far...

binmode should work.
 
S

sln

Does anyone have an idea how to do output single \n (0A) character
instead of \r\n (0D0A) in win32?
Let's say I do replacement:
s/newlinemarker/\n/mg
and want to substitute single character 0A
Windows implementation seems to always be smarter and uses 0D0A
automatically... How to prevent it?
I tried:
\n
\r
\x0a
\cJ
...nothing worked so far...

Well, you would like to write it out to a file in binmode, but
that doesen't mean you have to set binmode on a read file to manipulate
raw data internally.

-sln
-----------------------------------
use strict;
use warnings;

while (<DATA>)
{
s/\x{0d}\x{0a}|\x{0d}/\x{0a}/;
# to fixup stuff, say its mangled or something
# (the cart or the horse, pick your poison)
# s/\x{0a}\x{0d}/\x{0d}\x{0a}/;
print;
print ord($_), ' ' for ( split // );
print "\n\n";

# open a file for output (above 'while'), set to binmode,
# then write it out here with a ord/split.
}

__DATA__
line 1
line 2
line 3
line 4
---------------------
output:

line 1
108 105 110 101 32 49 10

line 2
108 105 110 101 32 50 10

line 3
108 105 110 101 32 51 10

line 4
108 105 110 101 32 52 10
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top