in reply to meta tag extraction with TokeParser
I'm already using TokeParser for scraping, so please don't suggest I also use TokeParser::Simple.
I don't understand this. Perhaps you weren't aware of this, but a deliberate design decision of HTML::TokeParser::Simple was to be a drop in replacement of HTML::TokeParser. Using my module means changing this:
use HTML::TokeParser; my $parser = HTML::TokeParser->new( \$src );
To this:
use HTML::TokeParser::Simple; my $parser = HTML::TokeParser::Simple->new( \$src );
After that change, all of your code still works. I did that deliberately so that folks could take advantage of the features of my module without having to rewrite their code. Your snippet changes from:
my %meta; my $htm2 = HTML::TokeParser->new( \$src ); while (my $token = $htm2->get_token) { next if $token->[1] ne 'meta' && $token->[0] ne 'S'; $meta{$token->[2]{name}} = $token->[2]{content}; }
To:
my %meta; my $htm2 = HTML::TokeParser::Simple->new( \$src ); while (my $token = $htm2->get_token) { next unless $token->is_start_tag('meta'); $meta{$token->get_attr('name')} = $token->get_attr('content'); }
I think most would agree that not only is this far more readable (and therefor far more maintainable). So if you're still not convinced, that's OK, but please don't try to suggest to others that HTML::TokeParser::Simple is not a good alternative to HTML::TokeParser. It's far easier to understand and use. You gain a lot and lose nothing.
Cheers,
Ovid
New address of my CGI Course.