in reply to Unable to read the sub direcctory using perl?
Hello gpssana,
Can you read (How do I post a question effectively?) and update your question?
Help us to help you, what you have tried? Errors? Help us replicate your problem.
Something like "Unable to read the sub direcctory using perl?" does not mean anything.
Update: I did a bit of search and I found this tutorial (Directory Recursion) written from the community. I have created a sample of code that reads my directory and sub directory and prints the contents that match my search.
Sample of code taken and modified from the tutorial:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub get_perl_files { my $path = shift; opendir (my $dh, $path) or die "Unable to open $path: $!"; my @files = map { $path . '/' . $_ } grep { !/^\.{1,2}$/ } readdir ($dh); return grep { (/\.pl/) && (! -l $_) } map { -d $_ ? get_perl_files ($_) : $_ } @files; } my @files_returned = get_perl_files("/home/tinyos/Monks"); print Dumper \@files_returned; __END__ $ perl test.pl $VAR1 = [ '/home/tinyos/Monks/test.pl~', '/home/tinyos/Monks/cmp.pl', '/home/tinyos/Monks/df.pl', '/home/tinyos/Monks/mySuDir/test_subdir.pl', '/home/tinyos/Monks/parallel_ssh.pl', '/home/tinyos/Monks/test_2.pl~', '/home/tinyos/Monks/sshutle.pl', '/home/tinyos/Monks/test_2.pl', '/home/tinyos/Monks/excel.pl', '/home/tinyos/Monks/test.pl', '/home/tinyos/Monks/parsingvalues.pl' ];
Update2: modifying DIR to my $dh.
Hope this helps.
|
|---|