WiktionaryDumps to words: Difference between revisions

m
(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
sub {
myforeach @Char_Array(split = split('', $_[0]) ;{
foreach (@Char_Array) {
my $status = $bz->bzinflate($_, substr($plain, 0)) ;
last if $status == BZ_STREAM_END or $status != BZ_OK ;
}
 
if ( scalar ( my @haystacks = split( "\n", $plain);) {
if ( scalar @haystacks ) {
$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>
 
350

edits