in reply to 2 Questions on File::Find

File::Find is a weird critter as it doesn't have a return value. This is a recursive descent deal that runs a subroutine on every file from starting directory. (note: that a directory name is a file!).

there is no return value from File::Find, you need to use a "global" var to get this...

here is example code.....

#!/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; } }
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".

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.