Perl Monk, Perl Meditation | |
PerlMonks |
Re: Restrict file search within current filessystem using wanted subroutineby haukex (Archbishop) |
on Apr 28, 2016 at 12:15 UTC ( [id://1161759]=note: print w/replies, xml ) | Need Help?? |
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.
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,
In Section
Seekers of Perl Wisdom
|
|