Hi madparu,

There is a little-known feature of File::Find from find2perl, the variable $File::Find::topdev, which holds the device number of the path currently being searched under, which you can compare with the device number of the current file (stat). Stick the following at the top of your wanted function, and your search will be limited to the filesystems of the paths which you tell File::Find::find to search under.

if ( $File::Find::topdev != (stat)[0] ) { $File::Find::prune = 1; return }

Update: Fixed stat vs. stat(_), apologies. My test code was doing a stat beforehand, so stat(_) worked fine. But if the piece of code above is the very first thing in your wanted function, you should stat $_ first, and only then use the special filehandle _. (The exception is when the follow option is set, then File::Find guarantees that an lstat has been called.)

And by the way, Use strict and warnings!

Hope this helps,
-- Hauke D


In reply to Re: Restrict file search within current filessystem using wanted subroutine by haukex
in thread Restrict file search within current filessystem using wanted subroutine by madparu

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.