Skip to content

Instantly share code, notes, and snippets.

@VienosNotes
Created October 20, 2017 18:06
Show Gist options
  • Save VienosNotes/2175136b7b480b281b3613bedc622c13 to your computer and use it in GitHub Desktop.
Save VienosNotes/2175136b7b480b281b3613bedc622c13 to your computer and use it in GitHub Desktop.
カードリストとwhisperから日本語名を付与するやつ
use strict;
use warnings;
use 5.18.2;
use File::Slurp;
use utf8;
use Encode;
my @legals = read_file("legal_cards.txt");
my $all_cards = read_file("search.php.txt", binmode => ":utf8");
my @all = split /\n\n/, $all_cards;
open my $fh, ">utf8", "namelist.txt";
foreach my $card (@legals) {
my $short;
if ($card =~ m{^(.*)\s//\s})
{
$short = $1;
} else {
$short = $card;
}
my $idx = -1;
foreach my $cand (@all)
{
++$idx;
last if index(lc($cand), "英語名:" . lc($short)) >= 0;
}
(my $removed) = splice @all, $idx, 1;
if ($removed) {
my @names = ($removed =~ m/日本語名:(.*?)(?:(.*?)?\n/g);
if ($names[1]) {
$fh->say("$card -> " . ("$names[0] // $names[1]"));
} else {
$fh->say("$card -> " . ($1 // "(日本語名なし)"));
}
} else {
say "something wrong in $card with $removed";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment