Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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
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 romping around the Monastery: (5)
As of 2014-07-29 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls