there is no return value from File::Find, you need to use a "global" var to get this...
here is example code.....
Your "wanted" sub should push @result, $File::Find::name if ( /hello\.txt$/ ) where @result has higher scope than sub with File:Find. There is no way for File::Find to use the return value of "wanted". You have to use a higher scoped var for this "return function".#!/usr/bin/perl -w use File::Find; use strict; my @dirs; find (\&dirs_deny_grp_other, $ENV{'HOME'}); print join ("\n",sort @dirs),"\n"; sub dirs_deny_grp_other { return if ! -d || !stat; if ( ( (stat "$File::Find::name")[2] & 011) == 0 ) { push @dirs, $File::Find::name; } }
Update: the above code looks for directories. It is more complex than what you need to do, but if you understand it, your code will be simple to do. Your code would return if -d (only look at files that are not directories). If you want to look at and find all files that match /hello\.txt$/i, you will have to look at every file in every sub-directory.
In reply to Re: 2 Questions on File::Find
by Marshall
in thread 2 Questions on File::Find
by bichonfrise74
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |