I\'m trying to traverse through all the subdirectories of the current directory in Perl, and get data from those files. I\'m using grep to get a list of all files and folder
Look at the -X operators:
perldoc -f -X
For directory traversal, use File::Find, or, if you're not a masochist, use my File::Next module which makes an iterator for you and doesn't require crazy callbacks. In fact, you can have File::Next ONLY return files, and ignore directories.
use File::Next;
my $iterator = File::Next::files( '/tmp' );
while ( defined ( my $file = $iterator->() ) ) {
print $file, "\n";
}
# Prints...
/tmp/foo.txt
/tmp/bar.pl
/tmp/baz/1
/tmp/baz/2.txt
/tmp/baz/wango/tango/purple.txt
It's at http://metacpan.org/pod/File::Next