TABを空白に変換

TABを、適当な数の空白に変換する。

SourceToHtml2.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); #空白に置き換え
}
print;
}

#フッタ部
open(F, ".\\Template\\footer.txt") || die "open: $!";
while ()
{
print;
}
close(F);

実行形式


C:\Perl5>SourceToHtml2.plx input.txt > output.txt