In a zone

gizmo_mathboy on 2002-06-06T20:33:49

I do love the feeling of fixing a ton of user requesst/defects. It certainly makes the day go by.

Although one fix felt a bit like voodoo.

I'm pulling some text out of mysql so the newlines are escaped. This string looks like:

$description = 'piece of text\r\nsome more text'

My hack is to do the following: $description =~ s/^'//; $description =~ s/'$//; $description =~ s/\\(['"])/$1/gso; $description =~ s/&/&/gso; $description =~ s//>/gso; $description =~ s/"/"/gso; $description =~ s/'/'/gso; $description =~ s/\\r\\n/\n/gso;

$description = Text::Autoformat::autoformat $description, {right => 50, fill => 0, squeeze => 0, all => 1, }; $description = pre( $description );


I was using escapeHTML() but that seemed to gobble some of the newlines.

I suppose I really should be posting this on ciwac instead of my journal...


regexps

gav on 2002-06-06T21:37:43

You don't need the 'os' modifiers for those regex's. You also might want to consider using:

for ($description) {
      s/foo/bar/;
      s/bleh/blah/;
      # etc
}

And something like:
my %subst = ( '&' => '&', '\\"' => '"');
s/$_/$subst{$_}/g for keys %subst;

I always have a nagging fear when I see 5 or more subsitutions in a row that something is up :)

Re:regexps

gizmo_mathboy on 2002-06-07T00:36:09

Nice ideas. I'll have to integrate them into my code. To be truthful I lifted most of them from escapteHTML from CGI.pm.

escapeHTML seemed to be chewing up some newlines so I lifted the bits that escaped the entities I wanted.

I really should put this one up on perlmonks and/or ciwac.