※hontai.pl コンバータ本体です。
use nsc_h2z;
~
略
~
nsc_h2z::nh2z("1.txt");
exit;
※nsc_h2z.pm 同梱するとかで
package nsc_h2z;
use utf8;
use Encode;
use Encode::JP::H2Z;
use open IO => ":encoding(cp932)";
sub nh2z{
my $file = $_[0];
open (local *IN,"$file");
open (local *OUT,">temp.txt");
while ( my $line = <IN> ){
if ( $line !~ /^[0-9a-zA-Z;\*\t]/ ){ # 命令文チェック
chomp $line;
my $text = $line;
my $tag;
if ( $line =~ /^(\[.*?\])(.*)/ ){ # タグ
$tag = $1;
$text = $2;
}
$text = Encode::encode("euc-jp",$text);
Encode::JP::H2Z::h2z(\$text);
$text = Encode::decode("euc-jp",$text);
$text =~ tr/?!a-zA-Z0-9/?!a-zA-Z0-9/;
$line = "$tag$text\n";
}
print OUT $line;
}
close IN;
close OUT;
rename "temp.txt","$file" if unlink "$file";
}
1;