in reply to question n File::Find
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: question on File::Find (cd)
by skyworld_chen (Acolyte) on Oct 31, 2012 at 01:43 UTC | |
by aitap (Curate) on Oct 31, 2012 at 15:50 UTC | |
by skyworld_chen (Acolyte) on Nov 01, 2012 at 12:55 UTC |