- 論壇徽章:
- 1
|
本帖最后由 yakczh_cu 于 2016-03-31 20:20 編輯
- use strict;
- use 5.01;
- use warnings;
- use File::Find;
- sub openit {
- my $path = shift;
- local *FH;
- return open (FH, $path) ? *FH : undef;
- }
- my @collect=();
- find(\&wanted,'yourpath');
- sub wanted{
- if($_ =~ /txt$/){
- my $fh;
- $fh=openit($File::Find::name);
- while(<$fh>){
- my @F=split/,/;
- unshift(@F,$F[2]);
- push(@collect,\@F);
- }
- close $fh;
- }
- }
- open(OUT,'>'.'destpath/out.txt') or die ("fila");
- say OUT join("\n", map { $_=join(',',@{$_}) } @collect);
- close OUT;
復(fù)制代碼 |
|