WiktionaryDumps to words: Difference between revisions
m
→{{header|Perl}}: simplify
(added Perl programming solution) |
m (→{{header|Perl}}: simplify) |
||
Line 497:
my %needles; my $plain = my $tail = '';
my $ua = LWP::UserAgent->new;
my $bz = new Compress::Raw::Bunzip2({ -Bufsize => 1, -AppendOutput => 0 });
my $res = $ua->request( HTTP::Request->new(GET => $URL),
sub { # @_ = Data Chunk, HTTP::Response
my $status = $bz->bzinflate($_, substr($plain, 0)) ;
last if $status == BZ_STREAM_END or $status != BZ_OK ;
}
if ( scalar ( my @haystacks = split
$haystacks[0] = $tail . $haystacks[0];
$tail = $haystacks[$#haystacks];
Line 516 ⟶ 513:
my ($title,$got_text_last) = '', 0 ;
foreach ( @haystacks[0..$#haystacks-1] ) {
if ( /<title>(\w+?)<\/title>/ ) {
($title,$got_text_last) = $1, 0;
Line 524 ⟶ 521:
$needles{$title}++ if ( $got_text_last and $title.defined );
if ( %needles >= $Target ) {
print "$_\n" for sort keys %needles;
exit;
}
Line 535 ⟶ 532:
{{out}}
<pre>
chien▼
gratis
pond▼
▲chien
gratuit
livre
▲pond
</pre>
|