加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

第一个perl程序

发布时间:2020-12-15 21:02:38 所属栏目:大数据 来源:网络整理
导读:http://bbs.csdn.net/topics/390272012 帮完成了这个问题,收藏下 use strict;use File::Find;use Getopt::Std;my @allcsvfile;my @targetfile;if($#ARGV == -1 ) { print "使用格式如下:perl list.pl 路径 关键字 保存文件路径n"; exit;}sub searchfile{

http://bbs.csdn.net/topics/390272012 帮完成了这个问题,收藏下

use strict;
use File::Find;
use Getopt::Std;

my @allcsvfile;
my @targetfile;

if($#ARGV == -1  ) 
{
   print "使用格式如下:perl list.pl 路径 关键字  > 保存文件路径n";
   exit;
}

sub searchfile
{
   my $path = @_[0];   
   open(MYHANDLE,$path);
   my @str = <MYHANDLE>;
	
	for my $k (@str)
	{
	    #print $k,"n";
		if($k =~ /.*$ARGV[1].*/)
		{
		   push @targetfile,$path;
		}
	}
   
}

sub test{
	if($_ =~ /.+.csv$/)
	{
		my $path = $File::Find::name;
        $path =~ s////g;
		push @allcsvfile,$path;
		
		searchfile($path);
		
	}
}

find &;test,"$ARGV[0]";

print "all csv file:n";
foreach (@allcsvfile)
{
   print $_,"n";
}

print "all target csv file:n";
foreach (@targetfile)
{
   print $_,"n";
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读