Last active
April 10, 2017 08:32
-
-
Save kurema/35c6849715bf8b9bd5d1d00776b8895c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use encoding "cp932"; | |
while(my $item=<STDIN>){ | |
if($item=~ /(<dfn>(.+?)<\/dfn>)/){ | |
my $dfn=$1; | |
my $txt=$2; | |
my $res=getKeys($txt); | |
$item=~ s/\Q$dfn\E/$dfn$res/g; | |
} | |
print $item; | |
} | |
sub getKeys{ | |
my $txt=$_[0]; | |
my $res=""; | |
my @words=split(/\s/,$txt); | |
for(my $i=0;$i<@words;$i++){ | |
my $word=$words[$i]; | |
if($word=~ /\//){ | |
my @ws=split(/\//,$word); | |
foreach my $w (@ws){ | |
my $tmp=""; | |
for(my $j=0;$j<@words;$j++){ | |
if($i==$j){$tmp.=$w;}else{$tmp.=$words[$j];} | |
$tmp.=" "; | |
} | |
chop $tmp; | |
if($tmp=~ /\//){ | |
$res.=getKeys($tmp); | |
}else{ | |
$res.="\n<key type=\"表記\">".$tmp."</key>"; | |
} | |
} | |
return $res; | |
} | |
} | |
return $res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment