in reply to Returning array of file names form find using local variables?

Hello,

that is not so easy, because File::Find seems to rely on global variables or closures for returning values. One way might be:

use File::Find (); # no namespace pollution my @startDirectories = ....; my @foundFiles = &FindFiles(@startDirectories); sub FindFiles { my @rootdirs = @_; my @foundFiles = (); File::Find::find sub { if (-f $File::Find::name){ # just files push (@foundFiles, $File::Find::name); } }, @rootdirs; return (@foundFiles); } # FindFiles
Haven't run this code, but hope that it will work.

Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

  • Comment on Re: Returning array of file names form find using local variables?
  • Download Code

Replies are listed 'Best First'.
Re: Re: Returning array of file names form find using local variables?
by Anonymous Monk on May 07, 2002 at 10:49 UTC
    mr. strat, thanks for the information. I have used the exactly what you have coded. I think that push command is the key. If I get back to you Mr. Hotshot comment, I am not really fond of global variables, just a skeeing the way to avoid it, if not then I will use what has been proposed. Thanks for your time and attention. Regards, Nevzat