Set $dirname to the path of the directory you want to search in and $search_string to the string you want to search for. Note: There is a problem with this script in that it will not strip html properly if there are nested tags for example the tag:use File::Basename; { local $/; opendir(DIR, $dirname) or die "Can't open directory $dirname: $!"; while (defined($file = readdir(DIR))) { ($base, $dir, $ext) = fileparse($dirname . "/" . $file,'\..*'); if ($file ne "." && $file ne "..") { #-T) { open(FILE, $dirname."/".$file) or die "Couldn't open $file: $!"; $plain_text = <FILE>; $plain_text =~ s/<[^>]*>//gs; if ($plain_text =~ /$search_string/g) { push(@matched_files, $base); } close(FILE); } } closedir(DIR); } # @matched_files contains all files that had $search_string in them
wouldn't be stripped properly. If this isn't going to be a problem though then the solution above should work fine. Good luck! Rob<img src="img.gif" alt=" Look at this >>>> ">
In reply to Re: Searching text files with strings
by r3b3lxd
in thread Searching text files with strings
by JohnMcPherson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |