Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

gizmo_mathboy (782)

  reversethis-{moc ... } {yobhtamomzig}

aerospace engineer by education, all-around walking cesspool of knowledge by nature, and professional grade slacker by choice. Sysadmin at a major midwestern university.
Thursday June 06, 2002
03:33 PM

In a zone

[ #5465 ]

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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • regexps (Score:2, Informative)

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

    for ($description) {
          # 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 :)
    • Nice ideas. I'll have to integrate them into my code. To be truthful I lifted most of them from escapteHTML from

      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.