in reply to Re^2: regex to replace linefeeds with <p> tags
in thread regex to replace linefeeds with <p> tags

I'll second Joost's approach, but make a few suggestions for readability / maintainability.
foreach my field (qw(postby title teaser content)){ $in{$field} =~ s[ (\r? \n){2,} ] # two or more CR [ \n </p> \n <p> \n]gx; # Close one para, open ano +ther }
throop

Replies are listed 'Best First'.
Re^4: regex to replace linefeeds with <p> tags
by ysth (Canon) on Dec 25, 2006 at 23:51 UTC
    Use [ ] braces for the the regex separator so you won't have to backslash the slash. This de-emphasizes some of the executable line noise effect
    I've long been of two minds about this. Consistency makes for readability, and I don't think I could sell everyone I share code with on always using some other delimiter, so I see a lot of advantage to always using / and escaping as needed (and the escaping does the job of pointing out that the following / is indeed literal, which is just what I want done.) On the other hand, that \ seems to bother a lot of other people, and they can't all be wrong, can they?