in reply to Tutorial on File::Find even more basic than "Beginners Guide"

When I first learned how to use File::Find, it took some getting used to. The documentation and everything else about it was fine, nevertheless I wrote a wrapper subroutine because I figured it could be made more readable to anyone who read my code but did not understand File::Find (or even perl for that matter).

Here is an example, it might help you, then again it might not.

### begin_: init perl use strict; use warnings; use File::Basename; use File::Find; ### begin_: process all files in the dir tree my $oDataTable = dirTreeToDataTable("c:/temp"); for my $oDataRec (@{$oDataTable}){ next unless $oDataRec->{extension} eq '.html'; ProcessTheFile($oDataRec->{path}); }
### begin_: subroutines ### <region-function_docs> ### main: ### - name : ProcessTheFile ### desc : fill_in_the_blank ### </region-function_docs> sub ProcessTheFile { my $sFilePath = shift || die "missing required argument path +."; ### munge your file however you want ### $sFilePath print "we finished mucking with $sFilePath\n"; }###end_sub ### begin: function docs ### <region-function_docs> ### main: ### - name : dirTreeToDataTable($startdir) ### desc : | ### Recurse all folders and files under start ### directory and return a listing. ### The return listing is a data table. ### Perl Array of Hashes (AoH). ### usage : | ### my $oDataTable = dirTreeToDataTable($startdir); ### </region-function_docs> sub dirTreeToDataTable{ my ($startdir) = @_; my @outArray = (); my $recNum = 0; if($startdir){ $startdir =~ s!(\\)!/!igm; # normalize to unix-style pat +hsteps }else{ return; } &find( sub { my @suffixlist = qw( \..* ); my ($basename,$path,$extension) = File::Basename::file +parse($File::Find::name,@suffixlist); ### INIT my $sTemp = $File::Find::name; my $pathsteps = ''; my $outrec = {}; ### dirTreeToDataTable_datarec_fields_ $outrec->{name} = "$basename$extension"; $outrec->{basename} = "$basename"; $outrec->{extension} = "$extension"; $outrec->{path} = "$File::Find::name"; $outrec->{dir} = "$path"; $outrec->{type} = (-f "$outrec->{path}")? +"file" : "dir"; $outrec->{size} = -s "$File::Find::name"; my @pathsteps = (split m!/!,$outrec->{pa +th}); $outrec->{depth} = scalar @pathsteps; $outrec->{startdir} = $startdir; push @outArray, $outrec; } ,$startdir ); return \@outArray; }###end_sub ### begin_: end perl 1; __END__