, &, |, (, ) を置換
<, >, &, |, (, ) を置換する。
SourceToHtml3.plx
#ヘッダ部
open(F, ".\\Template\\header.txt") || die "open: $!";
while ()
{
print;
}
close(F);#ソース部
while (<>)
{
while(($pos = index($_, "\t")) >= 0) #TABがあるか
{
$num = 4 - ($pos % 4); #空白何文字分に置き換えればよいか
$_ = substr($_,0,$pos).(' ' x $num).substr($_,$pos+1); #空白に置き換え
}# <, >, &, |, (, ) を置換
s/&/&/g; # &
s/</</g; # <
s/>/>/g; # >
s/\(/(/g; # ( はてな用
s/\)/)/g; # ) はてな用
s/\|/|/g; # | はてな用print;
}#フッタ部
open(F, ".\\Template\\footer.txt") || die "open: $!";
while ()
{
print;
}
close(F);
実行形式
C:\Perl5>SourceToHtml3.plx input.txt > output.txt