pp2@nereida:~/src/perl/testing$ syn.pl rehearsal rehersal rehearsalSigue el código:
pp2@nereida:~/src/perl/testing$ cat -n syn.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use WWW::Mechanize;
5 use HTML::Strip;
6
7 die "$0 word1 word2" if (2> @ARGV);
8
9 my $w1 = shift;
10 my $w2 = shift;
11 my $rw1 =checkres($w1);
12 my $rw2 =checkres($w2);
13
14 print $w1 , "\n" if ($rw1 > $rw2);
15 print $w2 ,"\n" if ($rw1 < $rw2);
16 exit;
17
18 sub checkres {
19 my $word = shift(@_);
20 my $w1 = WWW::Mechanize->new;
21 $w1->get('http://www.google.es/search?hl=es&q='.$word.'&meta=lr%3Dlang_es');
22 my $cont = $w1->content;
23 my $html = HTML::Strip->new;
24 my $limpio = $html->parse($cont);
25 $limpio =~ m/de aproximadamente ([\d.]+) páginas/ ;
26 $limpio = $1;
27 $limpio =~ s/\.//g;
28 return $limpio;
29 } # ---------- end of subroutine checkres ----------
Casiano Rodríguez León
