Using Perl File::Find

Friday, December 28, 2012 , 0 Comments

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:

use strict;
use warnings;

use File::Find;

find(\&print_name_if_dir, ".");

sub print_name_if_dir
print "$_"."\n" if -d && $_!~/^[\s]*\.[\s]*$/;