AlexPham AlexPham - 4 months ago 11x
Perl Question

Find:File in Perl - Search through symlink directory

Does anyone know how to make File:Find can search through symlink directory?

I have a real directory at


and a symlink directory inside

/home/alex/mydir1/test -> ../mydir2

Here is my code:

use strict;
use File::Find qw(find);

my $path = "/home/alex/mydir1";

find(\&Search,follow => 1, $path);

sub Search{
my $path = $File::Find::name;
print $path."\n";

And the result is:


Why it's not search through /home/alex/mydir2 and print out every files inside ? Can anyone show me how to do that ?

Thank you and best regards.



A close look at the documentation for File::Find reveals the error: You have passed an array of parameters instead of a hash reference of parameters.

# Incorrect: looks like find(@params)
# asks find to search the list of paths:
#    ( 'follow', 1, $path )
find(\&Search,follow => 1, $path);

# Correct: looks like find(\%params)
find({ wanted => \&process, follow => 1 }, $path);