Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re (tilly) 1: Why is this link parser only working the first time?

by dave_aiello (Pilgrim)
on Jan 20, 2001 at 01:19 UTC ( [id://53105]=note: print w/replies, xml ) Need Help??


in reply to Re (tilly) 1: Why is this link parser only working the first time?
in thread Why is this link parser only working the first time?

tilly:

Thanks very much. This is an excellent solution because the code change is limited to a single line.

What used to be:

sub attachment_link_extractor { my ($tag, %attr) = @_; push(@links, values %attr) if (($tag eq 'a') && ($attr{href} =~ m/attachments/)); } my $p = HTML::LinkExtor->new(\&attachment_link_extractor);
... now becomes ...
$attachment_link_extractor = sub { my ($tag, %attr) = @_; push(@links, values %attr) if (($tag eq 'a') && ($attr{href} =~ m/attachments/)); }; my $p = HTML::LinkExtor->new($attachment_link_extractor);
The only part of the your suggested change that confused me was the need to put a semicolon after the bracket that closes the subroutine. I don't remember ever writing Perl that way before, but, I keep forgetting that the subroutine itself is part of an assignment statement.

Dave Aiello
Chatham Township Data Corporation

Replies are listed 'Best First'.
Re (tilly) 3: Why is this link parser only working the first time?
by tilly (Archbishop) on Jan 20, 2001 at 15:31 UTC
    Sorry, I should have remembered the semi-colon. That is the kind of detail I stopped thinking about, they just automatically go in when I write, and if I edit then run I expect to have Perl catch.

    You are right about why you need it. In the language used in perlsyn, the subroutine is now within a "simple statement" and you need to terminate the statement.

    As for writing Perl like that, I do it all of the time and recommend it whenever I get the chance. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://53105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-25 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found