Skip to content

Instantly share code, notes, and snippets.

@gslin
Created December 6, 2010 18:26
Show Gist options
  • Save gslin/730691 to your computer and use it in GitHub Desktop.
Save gslin/730691 to your computer and use it in GitHub Desktop.
iwiki.pl
#!/usr/bin/perl
use 5.010;
use WWW::Wikipedia;
use strict;
use warnings;
main();
sub main {
my $jawiki = WWW::Wikipedia->new(language => 'ja');
while (<STDIN>) {
my $str = $_;
my $finalStr = $_;
while ($str =~ /\[\[(.*?)(\|.*)?\]\]/g) {
my $word = $1;
my $showWord = $2 // '';
my $entry = $jawiki->search($word);
if ($entry->raw =~ /\[\[zh:(.*?)\]\]/i) {
my $zhname = $1;
$finalStr =~ s{\Q$word$showWord\E}{$zhname}g;
}
}
print $finalStr;
}
}
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment