Why do you open the file just to close it again? You know -r can take a file name, not just a file handle, right?
Putting variables in quotes when you don't need to may bite you in future when you get to using references. But maybe you won't put variables containing references in quotes and so it is just a style issue.
But the main problem with your code is that $File::Find::name will often not be useful for opening a file (nor for checking the permissions on a file).
If you call File::Find's find() and pass it "foo" as the directory to search, then find() will chdir into the "foo" directory (by default) before doing much of any work. If you have a file "foo/bar", then your 'wanted' subroutine will be called with $_ set to "bar" and $File::Find::name set to "foo/bar".
Since your program is now cd'd into "foo", trying to open "foo/bar" would only work if you also had a "foo/foo/bar" file. So try:
sub wanted { print "hello 1\n" if -r $_; }
- tye
In reply to Re: question on File::Find (cd)
by tye
in thread question n File::Find
by skyworld_chen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |