Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Rebuilding changed tags with HTML::TokeParser

by Ovid (Cardinal)
on Dec 13, 2002 at 23:37 UTC ( [id://219779]=note: print w/replies, xml ) Need Help??


in reply to Rebuilding changed tags with HTML::TokeParser

Use HTML::TokeParser::Simple. First, I designed it to be a drop-in replacement, so you could use the module without any changes in your code except for the use statement and the constructor call. Then, as you refactor, you use the module to 'clean up' the nasty bits. The following is untested and assumes that the token is from HTML::TokeParser::Simple. It also requires the latest version because the "as_is" method is new.

my $tag; if ($change) { my $tag_type = $token->return_tag; my $attributes = make_attributes($token); $tag = "<$tag_type $attributes>"; } else { $tag = $token->as_is; } sub make_attributes { my $token = shift; my $seq = $token->return_attrseq; my $attr = $token->return_attr; return join ' ', map {qq|$_="$attr{$_}"|} @$seq; }

My version will also preserve the attribute sequence. Also note the the token, as mentioned, is still an array reference, so you can access them if you must, or do everything simpler by using the supplied methods. Since the token data is also the instance data, if you change the arrayref's data directly, you are also changing the instance data, which is why the above code still work.

Hmm... this gives me more ideas of what could be included in the module.

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://219779]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found