I've been struggling with HTML::LinkExtor for a while now, thanks to everyone who pointed me in its direction.

You can see the full documentation at http://search.cpan.org/author/GAAS/HTML-Parser-3.26/lib/HTML/LinkExtor.pm if you want to, but I'm just wondering what prompted the author to return the results as an array with a hash as the second item?

Here's the relevant section:

$p->links Returns a list of all links found in the document. The returned values will be anonymous arrays with the follwing [sic] elements: [$tag, $attr => $url1, $attr2 => $url2,...]

It's kind of confusing me. For a start, if it's a hash, shouldn't that be

[$tag, {$attr => $url1, $attr2 => $url2,...}]
instead?

And more to the point, I'm racking my not-inconsiderable knowledge of HTML to try and find a situation where a single tag could have two or more attributes which were links.

Apart from anything else, this structure leads to scary dereferencing being needed like this:

$p = HTML::LinkExtor->new(\&cb, "http://www.perl.org/"); sub cb { my($tag, %links) = @_; print "$tag @{[%links]}\n"; }

Maybe

@{[%links]}
isn't scary to you but it is to me...
--
($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;

In reply to Why Would HTML::LinkExtor return a hash of attributes? by Cody Pendant

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.