File: wikipedia

package info (click to toggle)
libwww-wikipedia-perl 2.05-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 248 kB
  • sloc: perl: 1,577; makefile: 4
file content (53 lines) | stat: -rwxr-xr-x 1,059 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl

=head1 NAME 

wikipedia - lookup an entry in the wikipedia

=head1 SYNOPSIS

    % wikipedia [-l lang] perl

=head1 DESCRIPTION

wikipedia is a command line tool for looking up a topic in the wikipedia
and printing it to STDOUT. Useful if you spend a lot of time in a shell
and don't want to fire up a web browser to see what something is.

=head1 AUTHORS

=over 4

=item * Slaven Rezic <slaven@rezic.de>

=back

=cut

use strict;
use WWW::Wikipedia;
use Text::Autoformat;
use Pod::Usage;
use Getopt::Std;

my %options;
getopts( 'l:', \%options );

my $term = shift;
pod2usage( { verbose => 1 } ) if !defined( $term );

my $wiki = WWW::Wikipedia->new( language => $options{ l } || 'en' );
my $entry = $wiki->search( $term );

## use a pager if we can
eval( 'use IO::Page' );
if ( $entry ) {
    my $text = $entry->text();
    if ( $text ) { print $text; }
    else {
        print "Specific entry not found, see also:\n";
        foreach ( $entry->related() ) { print " - $_\n"; }
    }
}
else { print qq("$term" not found in wikipedia\n) }