LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1088|回复: 1

打印 O'Reilly's perl books

[复制链接]
发表于 2004-1-20 15:07:52 | 显示全部楼层 |阅读模式
最近想把些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);
发表于 2004-1-20 15:32:22 | 显示全部楼层
呵呵~~~非常感谢laomie兄弟的原创。。。我们正缺这方面的内容呢!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表