in reply to Substitution outside of HTML TAGS
The new v3 API is nifty.
#!/usr/bin/perl -w use strict; use HTML::Parser; my $html; { local $/; $html = <DATA>; } my @parsed; my $p = HTML::Parser->new(api_version => 3, handlers => {default => [\@parsed, "event +,text"]} ); $p->parse($html); for (@parsed) { $_->[1] =~ s/poor/Perl/g if $_->[0] eq 'text'; print $_->[1]; } __DATA__ <HTML><HEAD><TITLE>poor hacker's almanac</TITLE></HEAD> <BODY BACKGROUND="poor.jpg"> <!-- poor comment --> <I>Just</I> Another <B>poor</B> Hacker. <poor tag> </BODY> </HTML>
|
|---|