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;).


    In reply to Re^3: file::find question by hipowls
    in thread file::find question by mikejones

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.