Here's an example using HTML::Parser
use strict; use HTML::Parser; use Data::Dumper; my $input = q{<tag ref=1>Start<tag ref=2>and more</tag>and end</tag>}; print "Input: [$input]\n"; my $p = HTML::Parser->new(api_version=>3, start_h=>[ \&startTokenHandler, "self,tokens" ], end_h=>[ \&endTokenHandler, "self,tokens" ], text_h =>[ \&textHandler, "self,dtext" ], ); $p->parse($input); sub startTokenHandler { my $self = shift; my $token = shift; printf("<%s %s=%d>\n", @$token); } sub endTokenHandler { my $self = shift; my $token = shift; printf("</%s>\n", $token->[0]); } sub textHandler { my $self = shift; my $text = shift; print "$text\n"; }
sample output:
$perl sample2.pl Input: [<tag ref=1>Start<tag ref=2>and more</tag>and end</tag>] <tag ref=1> Start <tag ref=2> and more </tag> and end </tag>
Hazah! I'm Employed!
In reply to Re: Split tags and words nicely
by osunderdog
in thread Split tags and words nicely
by bwgoudey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |