in reply to Re: How to Recursively search down thru directories to find a string and display its location.
in thread How to Recursively search down thru directories to find a string and display its location.

next if $File::Find::name eq '.' or $File::Find::name eq '..';

$File::Find::name contains the full path name so (in your example) it would start at ./. and continue with ./subdir/. etc. and would never match . or ...    Also you should use return when exiting from a subroutine.    Probably better as:

return unless -f;


open my $file, '<', $File::Find::name or die "Error openning file: + $!\n";

Also, because File::Find::find() changes directories, trying to open $File::Find::name from the current directory when using relative directory names won't work.    Just use the file name in $_:

open my $file, '<', $_ or die "Error openning '$_' $!\n";
  • Comment on Re^2: How to Recursively search down thru directories to find a string and display its location.
  • Select or Download Code