in reply to Why doesnt the string returned by $File::Find::name find point to files

Try removing all the cruft from your test code and report failures in a fashion that shows issues with white space in file names clearly. I notice that your code has fairly arbitary use of white space, including a space at the start of a (unused) path variable.

I also notice that the result you report can not have come from the code that you provided because the use of white space is different.

Try the following code and see if you can reproduce the error:

#!/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 +s print ">$File::Find::name< is not a file or was not found\n"; <p>}


DWIM is Perl's answer to Gödel
  • Comment on Re: Why doesnt the string returned by $File::Find::name find point to files
  • Download Code

Replies are listed 'Best First'.
Re^2: Why doesnt the string returned by $File::Find::name find point to files
by richill (Monk) on May 06, 2006 at 10:40 UTC
    I used this code. and got the error Substitution replacement not terminated at filefind_pm1.pl line 16. I changed the code to
    #!/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"}; }