How to match carriage returns and line feeds

S

Schroeder

I am using ActiveState's Perl on Windows and am trying to remove an excess
\x0d character I am getting (not sure why I am getting it, but doesn't
matter if I can easily be rid of it). What I see in my text is sequences of
\x0d\x0d\x0a - and I am trying to replace them with simply CRLF (\x0d\x0a).
I admit to being a newbie to Perl, so maybe I am just missing something.
Why wont the following work:

$text =~ s/\x0d\x0d\x0a/\x0d\x0a/gs;

Thanks

--Jeff--
 
J

Jim Gibson

Schroeder said:
I am using ActiveState's Perl on Windows and am trying to remove an excess
\x0d character I am getting (not sure why I am getting it, but doesn't
matter if I can easily be rid of it). What I see in my text is sequences of
\x0d\x0d\x0a - and I am trying to replace them with simply CRLF (\x0d\x0a).
I admit to being a newbie to Perl, so maybe I am just missing something.
Why wont the following work:

$text =~ s/\x0d\x0d\x0a/\x0d\x0a/gs;

It works for me:

#!/usr/local/bin/perl
#
use strict;
use warnings;

my $text = "abc\x0d\x0d\x0adef";
p("Before",$text);
$text =~ s/\x0d\x0d\x0a/\x0d\x0a/gs;
p('After',$text);
sub p
{
my($title,$text) = @_;
print "\n$title:\ntext=<$text>\n";
print join(' ',map { ord $_ } split(//,$text)),"\n";
}


__OUTPUT__
Before:
text=<abc
def>
97 98 99 13 13 10 100 101 102

After:
text=<abc
def>
97 98 99 13 10 100 101 102

You need to post a short program demonstrating the problem you are
having.

FYI; this newsgroup is defunct. Try comp.lang.perl.misc in the future.
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top