Skip to content

Instantly share code, notes, and snippets.

@fvox
Created July 10, 2012 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fvox/3086129 to your computer and use it in GitHub Desktop.
Save fvox/3086129 to your computer and use it in GitHub Desktop.
fork_call problem with ipc [fix'd]
#!/usr/bin/env perl
use common::sense;
use LWP::Simple;
use AnyEvent::Util;
use HTML::LinkExtor;
use Data::Printer colored => 1;
sub extract_links {
my @ret = ();
my $parser = new HTML::LinkExtor(
sub {
my ($tag, %links) = @_;
return if $tag ne 'a';
my ($url) = values %links;
push @ret, $url;
}
);
$parser->parse(get($_[0]));
return \@ret;
}
my $urls = [
qw(
http://terra.com.br/
http://g1.com.br/
http://r7.com.br/
http://uol.com.br/
)
];
my @pool = ();
my $cv = AnyEvent->condvar;
for my $url (@{$urls}) {
$cv->begin;
fork_call {
my $links = extract_links($url);
return $links;
}
sub {
push @pool, @{$_[0]};
$cv->end;
};
}
$cv->wait;
say 'POOL: ' . p(@pool);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment