读书人

Perl 资料操作

发布时间: 2012-11-13 10:00:51 作者: rapoo

Perl 文件操作

一:打开文件

#用户递归遍历$FilePath下所有文件和目录sub myOpen {   my($path) = @_;   if( -d $path ) {      # 打开目录 ?     opendir(DIR,$path) or die "Can't open $path. $!";      # 读取目录下所有文件     ?while( my @Files = readdir(DIR) ) {         foreach $file (@Files) {            # 过滤掉隐藏文件           ?next if $file =~ /^\./;            $eachFile = $path . $file . "/";            if( -d $eachFile ) {               #如果当前文件是目录,则递归遍历               &myOpen($eachFile);            } else {               #如果当前文件是普通文件,则解析之               &prase($path,$file);            }         }      }   } else {      print "error \n";      return 0;   }}

读书人网 >perl python

热点推荐