split function on CR/LF 
Author Message
 split function on CR/LF

I am trying to convert multiline text retrieved from an HTML Form's
textarea component into a single string where a comma and space replace
the CR/LF at the end of each line. My script runs:

...


print FILE "\""."$commatext"."\",";
...

However, something is wrong in the /\n/ regular expression in the split
function as it only seems to remove one byte of the original hex 0D 0A
pair that is in $multilinetext.

What regular expression should I use in the split function to remove
both bytes of the CR/LF pair?
--
Barney Tyrwhitt-Drake



Fri, 05 Jan 2001 03:00:00 GMT  
 split function on CR/LF


Quote:
> I am trying to convert multiline text retrieved from an HTML Form's
> textarea component into a single string where a comma and space replace
> the CR/LF at the end of each line. My script runs:

> ...
> # Remove CR/LFs in Address and replace them with comma+space


> print FILE "\""."$commatext"."\",";
> ...

> However, something is wrong in the /\n/ regular expression in the split
> function as it only seems to remove one byte of the original hex 0D 0A
> pair that is in $multilinetext.

> What regular expression should I use in the split function to remove
> both bytes of the CR/LF pair?

        \n is only the linefeed, not the carriage return and linefeed.

Try this:

        $multilinetext=~s/\r\n/, /g;

\r is the carriage return, \n the linefeed. which get replaced with a
comma and a space.

Brian Wheeler



Fri, 05 Jan 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Converting LF to CR+LF

2. DOS Perl convering LF to CR/LF

3. $/ = CR LF?

4. <FILE> and CR-LF

5. Binary data and CR-LF's in MSDOS

6. CR before login or any help that would lf before login

7. CR/LF

8. how to remove cr/lf ???

9. Question about formatting/(CR/LF) in PERL

10. Perl and CR+LF

11. Any Utility in Win32/Win95/Dos to remove CR or LF

12. CR LF to <br> in REGEX

 

 
Powered by phpBB® Forum Software