Perl - enhance code to recursively count files -
i new perl , trying larn language having hard time doing think simple.
i have been able script working count number of files in directory. enhance script recursively count files in sub directories also. have searched , found few different options glob , file::find, have not been able them work.
my current code:
#!/usr/bin/perl utilize strict; utilize warnings; utilize path::class; # set variables $count = 0; # set count start @ 0 $dir = dir('p:'); # p/ # iterate on content of p:pepid content db/pepid ed while (my $file = $dir->next) { next if $file->is_dir(); # see if directory , skip print $file->stringify . "\n"; # print out file name , path $count++ # increment count 1 every file counted } print "number of files counted " . $count . "\n";
can help me enhance code recursively search sub directories well?
the file::find module friend recursive kinds of operations. here's simple script counts files:
#!/usr/bin/perl utilize strict; utilize warnings; utilize cwd; utilize file::find; $dir = getcwd; # current working directory $counter = 0; find(\&wanted, $dir); print "found $counter files @ , below $dir\n"; sub wanted { -f && $counter++; # count files }
perl
No comments:
Post a Comment