Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
laziness, impatience, and hubris

Re: Using File::Find from a function.

by vinoth.ree (Vicar)
on Mar 19, 2013 at 06:23 UTC ( #1024213=note: print w/ replies, xml ) Need Help??

in reply to Using File::Find from a function.

From CPAN doc


find(\&wanted, @directories); find(\%options, @directories);

find() does a depth-first search over the given @directories in the order they are given. For each file or directory found, it calls the &wanted subroutine.Additionally, for each directory found, it will chdir() into that directory and continue the search, invoking the &wanted function on each file or subdirectory in the directory.


You can do this way.

my $file='foo'; my directory='a'; + sub check_existance { + if ( -e $_ && $_ eq $file ) { + print "Found file '$_' in directory '$File::Find::dir'\n"; + } + } find( \&check_existance, $directory );

The check_existance function takes no arguments but rather does its work through a collection of variables.


$_ is the current filename within that directory


The above variables have all been localized and may be changed without affecting data outside of the check_existance function.

Beginners guide to File::Find

All is well

Comment on Re: Using File::Find from a function.
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024213]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2014-03-14 01:07 GMT
Find Nodes?
    Voting Booth?

    Have you used a cryptocurrency?

    Results (293 votes), past polls