|
最近想把些mp3文件分割,合并,发现懂得一门shell编程很有必要,于是决定将perl大略学学。先从网上载下O'Reilly's perl books,本想将programming perl打印来看,但初始的.htm文件不方便打印,还好每个文件中我想打印的内容都有起始,结束的标志,于是写了段perl生成了方便打印的.htm。以下是简单的实现。
$tmpPath = "./temp";
opendir(DIR, $tmpPath) || die;
while (defined($dir = readdir(DIR)))
{
$newFile = substr($dir, 2, 2);
next if $dir !~ /ch(\w+)\.htm/;
$newFile = $newFile . ".htm";
open srcFile, "$tmpPath/$dir";
open desFile, ">>$newFile";
$isPrint = 0;
foreach $line (<srcFile>) {
if ($line =~ m%^<!-- SECTION BODY -->%) {
$isPrint = 1;
}
if (index($line, '<!-- BOTTOM NAV BAR -->') != -1) {
$isPrint = 0;
chop($line);
print desFile "$line\n";
}
if ($isPrint) {
chop($line);
print desFile "$line\n";
}
}
close srcFile;
close desFile;
}
closedir(DIR); |
|