in reply to File::Find wanted and preprocess together

And why can't you do the exclusion inside of "wanted" function?

  • Comment on Re: File::Find wanted and preprocess together

Replies are listed 'Best First'.
Re^2: File::Find wanted and preprocess together
by justinjoseph24 (Initiate) on Nov 03, 2010 at 17:04 UTC

    Not sure I understand what you mean.

    In the File::Find manpage, the preprocess routine is called before wanted. Are you implying that I could be using preprocess routine within the wanted routine? If so, could you please give an example?

      You don't use "bydepth" option. Which means that you can cancel processing of any subdirectory by setting $File::Find::prune=1. So, in your "wanted" function check if the file should be excluded from the processing and then set $File::Find::prune for the directories that should be excluded and simply ignore the files that should be excluded. Something like

      sub my_wanted{ if(exists $skip_them{$_}) { $File::Find::Prune = 1 if -d $_; return; } do_process($_); }

        Thanks for your reply, Andal. I added this logic to my script and it works. It's a great substitute for the 'preprocess' option. Now I can use follow => 1 and still process exclusions efficiently.