Here is a sample code:
use strict; use File::Find; my @dirs = qw( . ); ## add current directory to list of + dirs to search ## main processing done here my @found_files = (); my $pattern = qr/World/; find( \&wanted, @dirs ); ## fullpath name in $File::Find::name sub wanted { next if $File::Find::name eq '.' or $File::Find::name eq '..'; + open my $file, '<', $File::Find::name or die "Error openning file: + $!\n"; while( defined(my $line = <$file>) ) { if($line =~ /$pattern/) { push @found_files, $File::Find::name; last; } } close ($file); } ## display files - could be sorted if needed, etc foreach my $file( @found_files) { print $file, "\n"; }
In reply to Re: How to Recursively search down thru directories to find a string and display its location.
by diddy_perl
in thread How to Recursively search down thru directories to find a string and display its location.
by sharathfierof2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |