Chinaunix首页 | 论坛 | 博客
  • 博客访问: 398431
  • 博文数量: 57
  • 博客积分: 193
  • 博客等级: 入伍新兵
  • 技术积分: 1192
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-13 14:37
个人简介

当以艺术眼光看程序,寻找程序后面的原理,做到化而不忘

文章分类

全部博文(57)

文章存档

2017年(5)

2015年(7)

2014年(27)

2013年(18)

我的朋友

分类: 其他平台

2013-05-24 18:26:28

use strict;
my $CPPDir;
opendir($CPPDir,"D:\\GenCPPFile") || die("Cna not open dir:$!");
#得到的列表是包含.和..的,也就是i当前文件夹和父文件夹,所以要用grep去除这两项
my @TmpAllFiles=readdir($CPPDir);
#grep的本质就是for循环
my @AllFiles=grep(!/^\.\.?$/,@TmpAllFiles);
@AllFiles=grep(/\.cpp{0,1}/,@AllFiles);
my $FilePath;
my $FileHandle;
my $NewFileHandle;

chdir("D:\\GenCPPFile") || warn("D:\\GenCPPFile does not exist");
unlink <*.'p'>; #m删除文件,其前提是切换工作目录,因为默认目录为Perl目录
#system("del *.'p'");
foreach $FilePath (@AllFiles)
{
    open($NewFileHandle,">D:\\GenCPPFile\\$FilePath.'p'");
    open($FileHandle,"D:\\GenCPPFile\\$FilePath")|| die("Cna not open dir:$!");;
    while(<$FileHandle>)
    {
        #$_=~/^\s*$/查找空行
        if(($_=~/^\s*$/) || ($_=~/#line/) || ($_=~/__cdecl/) || ($_=~/extern/))
        {
           
        }
        else
        {
            print $NewFileHandle $_;
        }
    }
    close($NewFileHandle);#一定要关闭句柄,否则下面的system是不成功的
    close($FileHandle);
}

closedir($CPPDir);

system("del *.cpp");#system命令的前提是chdir进行目录切换
system("rename *.'p' *.cpp");
system("rename *.cpp *.");

 

阅读(2235) | 评论(0) | 转发(0) |
0

上一篇:VC笔记

下一篇:一点编程感悟

给主人留下些什么吧!~~