强大的Perl

 
由于项目需要,最近在学习Perl。很强大的东西,方便的文件读写,强大的字符串处理,随心所欲的语法格式,还有一个CPAN。
借了本精通正则表达式,一边学一边写。
早上还写了个脚本,放到启动项里,删除临时文件什么的,哈哈。
# !perl -w
#程序说明:Windows下,安装过ActivePerl的,可以把这个文件放在
#启动项里,每次启动都会清理Temp文件和最近的文档访问记录
#系统装在C盘的才可以用。。。
#代码大家自己看看吧,也不是很难。


use  File :: Path;

sub  get_cur_username() {
    
my   $cur_username ;
    
    
$cur_username   =  `set USERNAME`;

    
$cur_username   =~   / USERNAME = ( .* ) / ;
    
    
$cur_username   =  $ 1 ;

    
return   $cur_username ;
}

$usr   =  get_cur_username();
push  ( @paths , ' C:Documents and Settings/ ' . $usr . ' Recent/ ' );
push  ( @paths , ' C:Documents and Settings/ ' . $usr . ' Local SettingsTemp/ ' );
push  ( @paths , ' C:WINDOWSTemp/ ' );
# push (@paths,'C:Documents and Settings/'.$usr.'Local SettingsTemporary Internet Files/');

foreach   $path ( @paths ) {
                
                
opendir (DIR , $path ) or  die   " Cannot open The DIR: $! " ;
                
                
while  ( my   $name   =   readdir  DIR) 
                    {
                    
$filename   =   $path . " $name " ;
                    
print   $filename . " " ;
                                    
if  ( $filename !~   /.?. $ /
                                    {
                                        
if ( - $filename )
                                        {
                                        
unlink   $filename  or  print   " Can't delete :$! " ;
                                        }
                                        
else  
                                        {
                                        rmtree 
$filename ; #  or print "Can't delete :$! ";
                                        }
                                    }         

                    }
}

考虑用这个去分析Ogame的积分文件。。。恩恩。。。应该很好用,很华丽。。。

那天用来整理ORC录像文件,查找重复文件使用了MD5,导出CSV以后用Excel查找重复的MD5,很好用。

 

# 目录的深度优先遍历操作
#! perl -w

use  File :: Find;
print   " 请输入一个目录,不要太大 " ;
chomp ( $inputDir   =   < STDIN > );
open  (FILEOUT , ' >>F:orc.log ' );
my   @dir_array ;
push   @dir_array , $inputDir ;
open  (ORCDOCS , ' >>F:orcfiles.log ' );
open  (CSV , ' >>F:orc.csv ' );
# print FILEOUT "push DIR : $inputdir ";
while  ( my   $popdir   =   pop   @dir_array ) {
    
opendir  DIR , $popdir  or  print   " Can't open dir $popdir:$! " ;
    
while  ( my   $file   =   readdir  DIR) {
        
if  ( ' . '  eq  $file   ||   ' .. '  eq  $file ) {  next ; } 
        
# 拼接文件路径
         $file   =   " $popdir " . ' / ' . " $file " ;
            
if  ( - $file ) {
            
push   @dir_array , $file ;
            
# print FILEOUT "push DIR : $file ";
             print   " DIR: $file " ;
            
# print FILEOUT "DIR : $file ";
        
                }
        
else  {    
        
print   " File: $file " ;    
        
if  ( $file =~/ orc$ / i) {
            
print  ORCDOCS  " $file " ;
            
print  FILEOUT  $file . " " ;
            
print  CSV  " $file " . " , " ;
            
open  (FILEORC , $file ) or  die   " Error on Opening ORC FILE: $! " ;
            
$orcfile   =   < FILEORC > ;
            
while  ( $orcfile
                {
            
print  FILEOUT  $orcfile ;
            
$orcfile   =   < FILEORC > ;            
        }
close  FILEORC;
            
use  strict;
            
use  warnings;
            
use  Digest :: MD5;
            
my   $md5   =  Digest :: MD5 -> new();
            
open  ( HFILE ,   $file ) or  die  ( " Can't open:$! " );
            
binmode ( HFILE);              # 这一行也不能少
             $md5 -> addfile(  * HFILE);    # 不要忘记*号哦
             close ( HFILE);
            
my   $stringmd5   =   $md5 -> hexdigest() . " " ;
            
print  ORCDOCS  $stringmd5 ;
            
print  CSV  $stringmd5 ;
            
$md5 -> reset ();
        }

        }
    }
    
closedir  DIR;
    
print   " CloseDir " ;
}

 

 

继续学习。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值