agent00013 has asked for the wisdom of the Perl Monks concerning the following question:

Here's a bit of my code...
my($restrict) = "/web/.backup"; #don't go in here!! find(\&update,$somestartingdir); #find and execute sub on each file sub update { #blah, do whatever }
I can ignore individual files in the update sub by doing if ($pwd =~ /$restrict/) {}#skip it but is there a way to skip over the entire directory (and it's subdirectories) without touching any of the files (and, of course, continue processing other directories afterwards)?

Replies are listed 'Best First'.
Re: skip directories when using File::Find
by TGI (Parson) on Jun 27, 2001 at 04:43 UTC

    File::Find has a variable $File::Find::prune. When it's true, F::F won't descend into any subdirectories of the current directory.

    You might also want to monitor $File::Find::dir, if you want to descend inside your $restricted directories


    TGI says moo

      Thanks to your response and those of blakem, and DrZaius, I was able to fix it up. Thanx! (and for those too lazy to follow the link to the $File::Find::prune node, here's the code I got from it...
      if ($File::Find::name =~ m!^/some_dir/sub_dir!) { print "skipping $dir\n'; $File::Find::prune = 1; return; }
Re: skip directories when using File::Find
by blakem (Monsignor) on Jun 27, 2001 at 03:31 UTC
    Just from memory, I think there is a $File::Find::prune variable that will do this for you....
    if (skip_this_directory()) { $File::Find::prune = 1; }
    -Blake
Re: skip directories when using File::Find
by DrZaius (Monk) on Jun 27, 2001 at 03:55 UTC
    How about something like this:
    sub update { return if(m!^$restrict!o); # work here }
    You could switch it to a grep if you have a list of dirs to ignore as well.