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:

  1. invoked for every html file found the parser
  2. dumped for every embed tag encountered all attributes

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. }

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

In reply to Problem with HTML::Parser by Skeeve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.