in reply to Suppress 'Can't chdir to' warnings for File::Find

In your wanted() sub (near the top), it should work as you expect if you add a return if -d $File::Find::name && ! -x $File::Find::name;.

That checks to see if the current item is a directory, and checks whether the effective UID can traverse into it.

Replies are listed 'Best First'.
Re^2: Suppress 'Can't chdir to' warnings for File::Find
by mabossert (Scribe) on Apr 28, 2016 at 17:21 UTC

    Thanks for the alternative suggestion. I used the no warnings approach, but thought I would try yours as well. My logic was that maybe it would speed up processing, but surprisingly, it just about doubled the time from 6 secs to 11secs.

    That was totally unexpected! If I weren't knee deep in deadlines, I would explore why that is...speed is definitely of the essence for this function.

      My gut on the performance hit is stats the item in question twice. I could be COMPLETELY wrong on that though.

        There's a feature with stat() where it caches the item being tested on first call, to reduce overhead that would likely help reduce checking time. Note the _ at the end of the one-liner below. That's the cached item.

        perl -wMstrict -E 'say -f "utf.pl" && say -e _'

        Also, one could also look at the no_chdir => 1 feature of File::Find, however I don't know if one would get different warnings in that case, or if it'd just fail silently and move along when it encountered a restricted dir.