Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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]
[choroba]: Hermit
[haukex]: Ah I see... looks like "under construction" or something :-)
[Discipulus]: covfefe.. ? ;=)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2018-06-22 08:17 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (122 votes). Check out past polls.