Using Perl File::Find
Unix find command can be used as below for finding all the directory names from the current directort
find . -type d
Here I would like to present an example for doing the same in perl using the module File::Find.
This prints all the directory names in the current directory excluding the current directory using perl:
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
find(\&print_name_if_dir, ".");
sub print_name_if_dir
{
print "$_"."\n" if -d && $_!~/^[\s]*\.[\s]*$/;
}
0 comments: