swiftone has asked for the wisdom of the Perl Monks concerning the following question:
I have some code that alters A HREF tags/attributes inside an html document, and displays the results. I have it working fine, but there's a part where I'm sure there's an easier way to do it:
I have the code:
where $token is an HTML::TokeParser token for a starting A tag that contains an HREF attribute (otherwise $change is not set)my $tag; if($change){ #contruct modified tag # Wow this is ugly $tag = '<'.$token->[1].' '.join(' ',map({"$_ = '".$token->[2]{$_}."' +"} keys(%{$token->[2]}))).'>'; } else { #output original tag # This is nice $tag = $token->[0] eq "T" ? $token->[1] : $token->[-1]; }
Outputting unchanged tags is so elegant (idiom relayed to me by ChemBoy), surely there's a nicer way to convert a token I modify back into HTML? Thanks in advance.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Rebuilding changed tags with HTML::TokeParser
by Ovid (Cardinal) on Dec 13, 2002 at 23:37 UTC | |
Re: Rebuilding changed tags with HTML::TokeParser
by Ionizor (Pilgrim) on Dec 13, 2002 at 23:39 UTC |
Back to
Seekers of Perl Wisdom