http://www.perlmonks.org?node_id=935268


in reply to Re^4: Thanks to Ikegami, Chromatic & Corion
in thread Thanks to Ikegami, Chromatic & Corion

Erm... something ain't right, I just hacked your escapes code in and it's converted every "<" and ">" in the whole document!

output ------ &lab;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "ht +tp://www.w3.org/TR/html4/loose.dtd"&rab; &lab;html lang="en"&rab; &lab;head&rab; &lab;link href="/css/main.css" rel="stylesheet" type="text/css"&ra +b; &lab;null&rab; &lab;link href="/css/colours/daytime.css" rel="stylesheet" type="t +ext/css"&rab; &lab;script type="text/javascript" src="/js/ajax.js"&rab;&lab;/scr +ipt&rab; &lab;meta http-equiv="Content-Type" content="text/html; charset=ut +f-8"&rab; &lab;title&rab;Perl Nights&lab;/title&rab; &lab;/head&rab; &lab;body&rab; ... ...

Replies are listed 'Best First'.
Re^6: Thanks to Ikegami, Chromatic & Corion
by Logicus (Initiate) on Nov 02, 2011 at 02:33 UTC

    The escapes need to be the other way around!

    my %escapes = ( '&lab;' => '<', '&rab;' => '>', '&lcb;' => '(', '&rcb;' => ')', '&lsb;' => '[', '&rsb;' => ']' );

    I need a new escapes_re, because now it's simply destroying all the brackets!

      I need a new escapes_re, because now it's simply destroying all the brackets!

      Eeeep!

      A reply falls below the community's threshold of quality. You may see it by logging in.

      Got it!

      my %escapes = ( '&lab;' => '<', '&rab;' => '>', '&lcb;' => '(', '&rcb;' => ')', '&lsb;' => '[', '&rsb;' => ']' ); my $escapes_re = qr/&[lr][acs]b;/; $aXML =~ s/($escapes_re)/$escapes{$1}/g;

        That won't work. you need to handle those sequences, <special> and <post_include> at the same time, not before (which would break "&lab;special>lab&lab;/special>") or after (which would break "<special>lab</special>"). I've covered what would work elsewhere.

        A reply falls below the community's threshold of quality. You may see it by logging in.