pp2@nereida:~/src/perl/coro$ cat -n lwp.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Perl6::Say;
5
6 use Coro;
7 use Coro::Event;
8 use Coro::LWP;
9 use LWP::Simple;
10
11 $SIG{PIPE} = 'IGNORE';
12
13 die "Usage\n$0 url1 url2 ...\n" unless @ARGV;
14
15 my @pid;
16
17
18 for (@ARGV) {
19 push @pid, async {
20 my $site = shift;
21
22 say "Starting to fetch $site";
23 getstore("http://$site", "$site.html");
24 say "Fetched $site";
25 } $_;
26 }
27
28 $_->join for @pid;
pp2@nereida:~/src/perl/coro$ time lwp.pl www.google.com www.yahoo.com Starting to fetch www.google.com Starting to fetch www.yahoo.com Fetched www.yahoo.com Fetched www.google.com real 0m0.698s user 0m0.256s sys 0m0.056s pp2@nereida:~/src/perl/coro$ ls -ltr | tail -2 -rw-r--r-- 1 pp2 pp2 9562 2008-05-01 12:47 www.yahoo.com.html -rw-r--r-- 1 pp2 pp2 7191 2008-05-01 12:47 www.google.com.html
Casiano Rodríguez León
