in reply to Re^2: file::find question
in thread file::find question

There are three possible actions

  • do not process
  • process and prune
  • process and do not prune
  • It seems to me that your cases are

  • / root directory, do not prune
  • /var /usr/local an absolute path where the top level directory has a name beginning with a-z A-Z or _, prune
  • every thing else e.g. .ssh /.kde tmp ../etc /+share, ignore
  • if ( $fs eq '/' ) { # only if the root directory my_find( $fs, 0 ); } elsif ( $fs =~ m|^/\w+| ) { # matches /var my_find( $fs, 1 ); } else { # everything else which we ignore # /.ssh # tmp # working/data # /-etc } sub find_me { my @directory = shift; # play nicely with others local $File::Find::prune = shift; <snip> }

    If these are not the cases that you want to match I strongly suggest that you think clearly about what you are trying to match. Are relative paths allowed? How about the tmp directory in your current working directory (no / in the path)? Is there a need to restrict directory names to beginning with word characters?

    Note that I pass parameters to find_me() rather rely on global variables, find_me() can now be used from elsewhere in the program. Also I localize $File::Find::prune so that changes to File::Find within find_me() don't leak out into the rest of your program. If you don't do that you will have to remember to explicit reset $File::Find::prune before you use any Find::File function elsewhere (or spend hours debugging;).

    Replies are listed 'Best First'.
    Re^4: file::find question
    by mikejones (Scribe) on Jan 05, 2008 at 15:23 UTC
      I understand now. Excuse me for having a hard time putting that into words you could understand. Thank you!
    Re^4: file::find question
    by mikejones (Scribe) on Jan 08, 2008 at 03:11 UTC
      Shouldn't prune be set to 1 for true as in DO NOT desend dirs? From the man page "-prune" Do not descend into the directory currently matched. I ask b/c I ran these CLIs manually to look at Deparsed code and b/c my code is desending when "/" is used as input.
      /etc/skel$ find2perl /cygdrive/c/temp -size +4092k -ls -prune use strict; use File::Find (); use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; sub wanted; sub ls (); my @rwx = qw(--- --x -w- -wx r-- r-x rw- rwx); my @moname = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my (%uid, %user); while (my ($name, $pw, $uid) = getpwent) { $user{$uid} = $name unless exists $user{$uid}; } my (%gid, %group); while (my ($name, $pw, $gid) = getgrent) { $group{$gid} = $name unless exists $group{$gid}; } # Traverse desired filesystems File::Find::find({wanted => \&wanted}, '/cygdrive/c/temp'); exit; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && (int(((-s _) + 1023) / 1024) > 4092) && ls && ($File::Find::prune = 1); }