[Chicago-talk] array to hash and counting files

Jeremy Hubble jhubble at core.com
Tue Dec 30 11:59:11 CST 2003

I have a series of directories that each have a number of 
subdirectories with the same directory structure.  I need to count the 
number of files and directories in each subdirectory, and get a list of 
all unique files.

Here is the code fragment I have (not tested yet):

Is there a more effecient way to:
1) Extract the unique list of files?
2) Use perl to replace the find commant?



my $d_count=0;
my $f_count=0;
my %map;
opendir (ED_DIR, $bdir);
@subdir = { /!^\./ && -d "$bdir/$_" } readdir(DIR);
        foreach $d (@subdir) {
                chomp $d;
                my $dir = "$bdir/$d";
                my @files = qx~find $bdir -type 'f' -print~;
                my @dirs = qx~find $bdir -type 'd' -print~;
                foreach $f (@files) {
                      $map{$f} = 1;



More information about the Chicago-talk mailing list