Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How to remove a carriage return (\r\n)

by pg (Canon)
on Nov 01, 2005 at 16:30 UTC ( #504638=note: print w/ replies, xml ) Need Help??


in reply to How to remove a carriage return (\r\n)

To be a little bit cross-platform, just do:

use strict; use warnings; { my $str = "abcd\r\n"; $str =~ s/\r|\n//g; print "[$str]"; } { my $str = "abcd\n"; $str =~ s/\r|\n//g; print "[$str]"; } { my $str = "abcd\r"; $str =~ s/\r|\n//g; print "[$str]"; }


Comment on Re: How to remove a carriage return (\r\n)
Download Code
Re^2: How to remove a carriage return (\r\n)
by jgallagher (Pilgrim) on Nov 01, 2005 at 18:44 UTC
    But what happens when $str = "ab\ncd\r\n"? Or can we assume there are no line breaks except at the end of lines?
      $line =~ s/\R//g;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://504638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-12-29 04:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls