sub GetWikipediaAbstract { my ($query) = @_; $query = &EncodeString($query); my $SearchURL = $WikipediaAPI_URL.$query; my $ua = LWP::UserAgent->new; $ua->timeout(1); $ua->agent('$ScriptUserAgent'); my $response = $ua->get($SearchURL); if ($response->is_success) { my $content = $response->decoded_content; $content = &EncodeUTF8($content); my $json_obj = JSON->new(); my $perl_data = $json_obj->decode($content); # return undef in case of invalid data return undef if ref( $perl_data->{query}{pages} ) ne 'HASH' ); my ($jsonHash) = values %{ $perl_data->{query}->{pages} }; my $text = $jsonHash->{extract} || 'kein Ergebnis erhalten'; # in case of ( 0, undef, or '' ) insert own text return $text; } }