richill has asked for the wisdom of the Perl Monks concerning the following question:
I am asking because this code will not work as i want. The file tests always return false.
#!/usr/local/bin/perl -w # print warnings use strict; use File::Find; my $Start_dir = shift; die ">$Start_dir< is not a directory\n" if !-d $Start_dir; find( \&process, $Start_dir ); sub process { return if -f $File::Find::name; # This is success - the file exi +st return if -e $File::Find::name; print ">$File::Find::name < is not a file or was not found\n"; }
This code works as I expected
#!/usr/local/bin/perl -w use strict; use File::Find; my $Start_dir = shift; my @found =(); die ">$Start_dir< is not a directory\n" if ! -d $Start_dir; find(\&process, $Start_dir); sub process { push(@found, $File::Find::name) } foreach (@found){ if (-d $_ ) { print "This is success - the directory $_ exist\n"}; if ( -f $_) { print "This is success - the file $_ exist\n"}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using file::find::name and file tests
by merlyn (Sage) on May 06, 2006 at 17:25 UTC | |
by davidrw (Prior) on May 06, 2006 at 17:35 UTC | |
by bart (Canon) on May 06, 2006 at 20:28 UTC | |
by davidrw (Prior) on May 07, 2006 at 14:00 UTC | |
by richill (Monk) on May 07, 2006 at 21:40 UTC | |
by Hue-Bond (Priest) on May 07, 2006 at 21:46 UTC | |
by parv (Parson) on May 07, 2006 at 22:01 UTC | |
|
Re: using file::find::name and file tests
by GrandFather (Saint) on May 06, 2006 at 18:07 UTC | |
|
Re: using file::find::name and file tests
by davidrw (Prior) on May 06, 2006 at 17:28 UTC |