On Sep 9, 2004, at 9:57 AM, Chris Devers wrote:

This is why I like to use something other than a slash when trying to match html or xml:

    $details =~ s#\r#<br />#g;

Also, did you really mean to replace '\r' with '<br />' ? That will, depending on the file encoding, either [a] do nothing, or [b] strip out all the carriage returns, flatten the file into one line of ascii with html break tags every now and then. I suspect you probably didn't mean to do either of these, but rather:

    $details =~ s#\n#<br />\n#g;

Which should portably add a break tag to the end of each source line.


Actually, I think what I meant was:

$details =~ s/\r/<br \/>\n/g;

I like to stick with / because it looks prettier.  :)

Sorry 'bout missing escaping the / - rather jet lagged at the moment. However, in his use, it shouldn't really matter that the carriage returns are

HTML parsing is a real bear to get right. For a limited problem like this, mucking around with regular expressions isn't so bad, but if you really want to do it right, it's worth pulling in a parsing engine like HTML::Parser or HTML::TreeBuilder or something along those lines...


Yes, if you are going to parse a lot of HTML it's worth using a parsing engine. But, as I understood the initial question, it was just for debugging purposes. Hence, not worth the time to download and install a module and add another extra requirement to the project. Actually, strictly speaking, it shouldn't matter if you leave the result all on one line or not.


I do prefer to replace \r instead of \n, because you only want to replace the hard returns entered in the <textarea>, and allow the rest to flow normally. Historically, some browsers have inserted a \n when the text in a <textarea> set to wrap=virtual soft-wraps.


Chad A Gard http://www.percussionadvocates.com/chad


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to