[Chicago-talk] MJD replies...

Andy Lester andy at petdance.com
Tue Dec 6 11:50:01 PST 2005


Subject: Re: HOP page 191 
Date: Tue, 06 Dec 2005 13:47:49 -0500
From: Mark Jason Dominus <mjd at plover.com>


> Just trying to figure this out:
> sub traverse {
>   my $interesting_links  = sub { @_ };
>   $interesting_links = shift if ref $_[0] eq 'CODE';
> ....
>    push @queue, $interesting_links->(get_links($url, $html));
> 
> so, if I *don't* pass a sub ref as the first param, $interesting links 
> will be a ref to a sub of the list of URLs? How is that going to work w/ 
> get_links?

$interesting_links is a function that gets a bunch of URLs and returns
only the ones that are interesting.  By default, it returns
everything.

If you pass a function as the first argument to traverse(), the default
$interesting_links function is replaced with the argument function.

The replacement function should still be prepared to accept a list of
URLs and to return the ones that are interesting.

get_links() returns a list of URLs, which are passed to the
interesting_links function.  The default interesting_links function
returns all the URLs it was passed.




------- End of Forwarded Message


----- End forwarded message -----

-- 
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance


More information about the Chicago-talk mailing list