in reply to Re: Why doesnt the string returned by $File::Find::name find point to files
in thread Why doesnt the string returned by $File::Find::name find point to files
#!/usr/local/bin/perl -w # force taint checks, and 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 -d $File::Find::name; return if -f $File::Find::name; # This is success - the file exist print ">$File::Find::name< is not a file or was not found\n"; }
this gave the error for every file in the directory.
>testdir/nitcnitc Folder/nitcnitc/0wireless.html< is not a file or was not found
It looks like the -f and the -d flags are not working.
I'm using osx I maybe i should be using mac:perl. I thought this was just for people using classic but it looks like im wrong.
Acually running returns the expected results
#!/usr/local/bin/perl -w # force taint checks, and 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 -e $Start_dir # return if -f $File::Find::name; # This is success - the file ex +ist # return if -e $File::Find::name; print ">$File::Find::name < is not a file or was not found\n"; }
It looks like $File::Find::name cannot be used as a value for a file test.
If i save the strings returned from £file::find::name, to an array then work through the array then filetests seem to work. Why is this
#!/usr/local/bin/perl -w # force taint checks, and print warnings 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"}; }
|
|---|