I am new to Perl and I am trying to list all the folders within a given folder and I have the following code. I know it is simple but for some reason the program just stops and I am not seeing any error code being returned.
Does anybody have a good example of File::Find that they are willing to share. Examples are easier for me to follow.
#!/usr/bin/perl
#
use warnings;
use strict;
use File::Find;
my $path_name;
$path_name = '/test';
find sub {
return unless -d;
print "$File::Find::name\n";
Dirk <dirk.de...@usa.net> writes:
> I am new to Perl and I am trying to list all the folders within a
> given folder and I have the following code. I know it is simple but
> for some reason the program just stops and I am not seeing any error
> code being returned.
> I am new to Perl and I am trying to list all the folders within a given
> folder and I have the following code. I know it is simple but for some
> reason the program just stops and I am not seeing any error code being
> returned.
> Does anybody have a good example of File::Find that they are willing to
> share. Examples are easier for me to follow.
You don't need to call 'exit' unless you want to exit early, or with an
error code. Falling off the end of a Perl program is the usual way to
exit successfully.
This program works correctly for me, with or without the 'exit'. How
exactly are you invoking it, and what output do you see?
> I am new to Perl and I am trying to list all the folders within a given
> folder and I have the following code. I know it is simple but for some
> reason the program just stops and I am not seeing any error code being
> returned.
> You don't need to call 'exit' unless you want to exit early, or with an
> error code. Falling off the end of a Perl program is the usual way to
> exit successfully.
JFTR: This is not necessarily always true. For instance, the embedded
perl interpreter Nagios may use for executing plugins written in Perl
complains about plugins which didn't exit 'properly' if there is no
explicit exit statement at the end of the code.
> I am new to Perl and I am trying to list all the folders within a given folder and I have the following code.
> I know it is simple but for some reason the program just stops and I am not seeing any error code being returned.
> #!/usr/bin/perl
> #
I'm home now and I went as far as making "/test" and a couple of subdirectories on my personal machine, and ran your code exactly as it is, superfluous "exit" statement and all. It runs perfectly. So you have another problem; if you'd reply to some of the posts we'll try to help you with it.
Thanks to everybody for their input. When I first ran the code I was running it for a folder that did not have a lot of sub-folders. When I ran it agains a very large folder I could not verify all folders and it appeared that I had some missing folders. After being able to verify all the folders and it appears that the code did return all sub-folders.
However, I did notice that I am getting a permission error. Something about not being able to change directory.