On Thu, 9 Sep 2004, Chad A Gard wrote:

Try this:

$details = param('details');
$details =~ s/\r/<br />/g;

Careful now...

    $ perl -e '$details = "foo"; $details =~ s/\r/<br />/g;'
    Search pattern not terminated at -e line 1.
    $

The '/' in '<br />' needs to be escaped, or the regex is unbalanced.

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.



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



--
Chris Devers

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