LinuxSir.cn,穿越时空的Linuxsir!

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

分解 patch 的脚本。perl。

[复制链接]
发表于 2006-3-24 13:07:01 | 显示全部楼层 |阅读模式
用了一下,还好,就是把一个大的patch集合分解开来,有的时候挺方便的。

  1. #!/usr/bin/perl
  2. #
  3. # simple script to split a diff in one file
  4. # for each touched file

  5. while(<>) {
  6.         if (/^---/) {
  7.                 @a = split(/[ \t]+/);
  8.                 $fn = $a[1];
  9.                 $fn =~ tr/\//_/;
  10.                 if (-e $fn) {
  11.                         $i = 1;
  12.                         while(-e "$fn.$i") {
  13.                                 $i++;
  14.                         }
  15.                         $fn .= ".$i";
  16.                 }
  17.                 print $fn;
  18.                 print "\n";
  19.                 close OUT;
  20.                 open OUT, "> $fn" or die "Couldn't open $fn";
  21.                 print OUT $buffer;
  22.                 $buffer = "";
  23.         }
  24.         if (/^[+\- @]/) {
  25.                 print OUT $_;
  26.         } else {
  27.                 $buffer .= $_;
  28.         }
  29. }
复制代码
发表于 2006-3-24 13:57:55 | 显示全部楼层
多谢了,有段时间不写perl,正好复习一下,呵呵
回复 支持 反对

使用道具 举报

发表于 2006-3-24 23:06:04 | 显示全部楼层
hey幻想,since its perl, I will just move it to perl sub forum.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-25 06:12:15 | 显示全部楼层
oh, thanks. I forgot the perl sub-forum...:beat
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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