in reply to Supplying the RHS to a regex as a variable
use HTML::Parser; use strict; my $str = '<p>something something</p> <h2>blah <<< blah blah</h2> <p>something something</p>'; my $parser = HTML::Parser->new(default_h=> [\&handler, "tagname, text" +]); $parser->parse($str); sub handler { my ($tag, $text) = @_; if ($tag) { if ($tag eq "h2") { print "<h1>"; } else { print "<$tag>"; } } else { print $text; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Supplying the RHS to a regex as a variable
by BUU (Prior) on Oct 18, 2003 at 07:19 UTC | |
|
Re: Re: Supplying the RHS to a regex as a variable
by Cody Pendant (Prior) on Oct 18, 2003 at 07:43 UTC |