Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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; } }


Cheers,
Rupesh.


Comment on Re: Finding Files and Processing them iteratively
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://434437]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2015-07-31 03:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls