Skeeve has asked for the wisdom of the Perl Monks concerning the following question:
I have a problem using HTML::Parser. Maybe I'm missing something plain obviouse, but I don't see it. I have to say that it's the first time ever I use HTML::Parser.
What I thought I've done in the script shown below is:
But what I really get is, for each embed tag in every file found, just one attribute.
Can someone please hit my head aginst the parts where I made a mistake?
#!/usr/bin/perl use strict; use warnings; use HTML::Parser; use File::Find; use Data::Dumper; my $hp= HTML::Parser->new( api_version => 3, start_h => [ \&start, 'tag,attr' ], # This should call, for every start tag the start subroutine # passign the tagname and a reference to the attribute hash ); find( sub { return unless /\.html?$/; find_embed( $_ ); # in find_embed I will invoke the parser }, @ARGV) if scalar(@ARGV); sub find_embed { my($filename)= @_; $hp->parse_file( $filename ); # Now the parser is started } sub start { my($tag, $attr)= @_; return unless $tag eq 'embed'; # ignore every tag but embed print Dumper($attr); # Dump the attributes. }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problem with HTML::Parser
by Skeeve (Parson) on Jan 30, 2007 at 15:50 UTC | |
by holli (Abbot) on Jan 30, 2007 at 16:16 UTC |