in reply to Search a perl reference and replace characters

Further more the input listed is in:

my $text = "above"

Huh?

Do you wish to convert 'newlines', or 'carriage returns'? My guess is probably newlines. If that's the case, you may be looking for something like this:

$input =~ s{\n}{</p&rt;<p&tk;}g

Or maybe you really do mean carriage returns, in which case it would be:

$input =~ s{\r}{</p&rt;<p&tk;}g

Your entities look funny to me though, but that's a different issue.

Regular expressions, including 'substitutions' are covered in perlre, perlrequick, and perlretut. Those documents will go a long way toward clearing the haze regarding string manipulation and pattern matching in Perl. They're well worth the time they take to read.


Dave

Replies are listed 'Best First'.
Re^2: Search a perl reference and replace characters
by ww (Archbishop) on Jun 02, 2006 at 18:06 UTC
    my guess (from the context) is that OP has typos repeatedly; that intent was for each of those
      &rt;
    was meant to be:
      >
Re^2: Search a perl reference and replace characters
by Anonymous Monk on Jun 02, 2006 at 13:22 UTC
    I always go for the safe approach ...
    Pseudocode ...
    Find Replace chr(13).chr(10) with "<br>";
    Find Replace chr(13) with "<br>";
    Find Replace chr(10) with "<br>";

    This seem to cover Winslows, Mac and Unix flavours of text input ...