Skip to content

Instantly share code, notes, and snippets.

@kurema
Last active April 10, 2017 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurema/35c6849715bf8b9bd5d1d00776b8895c to your computer and use it in GitHub Desktop.
Save kurema/35c6849715bf8b9bd5d1d00776b8895c to your computer and use it in GitHub Desktop.
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