in reply to Stripping font "face" values from font tags

Fish.

use HTML::TokeParser (); my %verb = ( S => 4, E => 2, T => 1, C => 1, D => 1, PI => 2 ); my $p = HTML::TokeParser->new( "foo.html" ) or die "can't open foo.html: $!\n"; while( my $t = $p->get_token ) { if( $t->[0] eq 'S' and $t->[1] eq 'font' ) { my $attr = $t->[2]; delete $attr->{face}; print "<font ", join( " ", map { qq{$_="$attr->{$_}"} } keys %{$attr} ), ">"; } else { ## print verbatim . . . print $t->[ $verb{ $t->[0] } ] } } exit 0; __END__

Replies are listed 'Best First'.
Re: Re: Stripping font "face" values from font tags
by Ovid (Cardinal) on May 28, 2003 at 16:41 UTC

    Nice code. It's even easier with HTML::TokeParser::Simple, though.

    use HTML::TokeParser::Simple; my $p = HTML::TokeParser::Simple->new( "foo.html" ) or die "can't open foo.html: $!\n"; while( my $t = $p->get_token ) { if( $t->is_start_tag('font') ) { my $attr = $t->return_attr; delete $attr->{face}; my $attributes = join( " ", map { qq{$_="$attr->{$_}"} } keys +%$attr ); print "<font $attributes>"; } else { print $t->as_is; } }

    Cheers,
    Ovid

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