How to match carriage returns and line feeds

Discussion in 'Perl' started by Schroeder, Jan 26, 2005.

  1. Schroeder

    Schroeder Guest

    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--
    Schroeder, Jan 26, 2005
    #1
    1. Advertising

  2. Schroeder

    Jim Gibson Guest

    In article <LtPJd.28135$>,
    Schroeder <> wrote:

    > 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.


    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= East/West-Coast Server Farms - Total Privacy via Encryption =---
    Jim Gibson, Jan 26, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Olurotimi Ige
    Replies:
    2
    Views:
    477
    Patrick Olurotimi Ige
    May 5, 2005
  2. Replies:
    3
    Views:
    896
    John C. Bollinger
    Jan 17, 2005
  3. Bazza Formez
    Replies:
    2
    Views:
    917
    Bazza Formez
    Aug 6, 2007
  4. Replies:
    3
    Views:
    4,895
    Peter Bromberg [C# MVP]
    Mar 6, 2008
  5. Steve Anderson
    Replies:
    3
    Views:
    239
    Steve Anderson
    Jun 21, 2004
Loading...

Share This Page