Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Finding Files and Processing them iteratively

by rupesh (Hermit)
on Feb 25, 2005 at 12:40 UTC ( #434437=note: print w/replies, xml ) Need Help??

in reply to Finding Files and Processing them iteratively

You can also use File::Find or File::Recurse.
#!c:\perl\bin\perl.exe use strict; use File::Recurse; use File::Find; my (@filearr, $path, $prod_file, $files, %files, %all); sub recurse { my $path=shift; my $matchpattern=shift; %files = Recurse(["$path"], { match => "$matchpattern", nomatch => '' }); if (scalar keys %all) { @all{keys %files} = values %files; } else { %all=%files; } } { recurse("c:\\data", "\."); foreach (sort keys %all) { my $dirs=$_; foreach (@{ $all{"$_"} }) { $files=$_; my $fullname="$dirs"."\\"."$files"; push @filearr, "$fullname\n"; } } foreach my $machine (@filearr) { chomp; open FH, "<$machine"; my $ctr=0; foreach (<FH>) { chomp; $ctr+=$_; } close FH; $all{$machine}=$ctr; } }


Replies are listed 'Best First'.
Re^2: Finding Files and Processing them iteratively
by satchm0h (Beadle) on Feb 25, 2005 at 13:24 UTC
    If you decide to go with File::Find and are Unix find savvy, check out the handy find2perl script. Write a find command line that does what you want and then replace 'find' with 'find2perl' and it will generate the code for you.

    Although for your specific task, File::Find may be overkill. The various glob solutions others have posted should serve you well.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://434437]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2017-12-17 14:40 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (464 votes). Check out past polls.