#!/usr/local/bin/perl

# search for a file in all subdirectories
#

$file_ext = '.html';

# match for ' speech and any digit'
#
@strings = ('speech','and','\d');

# look in current directory
#
$dir = "/cavs/hse/ies/www/";
chop($dir);

# calling a subroutine to serch the directory
#
&search_directory($dir); 

# definition of the subroutine
#
sub search_directory {
local ($dir);
local(@lines);
local($lines);
local($count);
local(@lines_in_file);
local($lines_in_file);
local ($file_name);
local($subdir);
local($file);


$dir = $_[0];

# search this directory
#

@lines = `cd $dir; ls -l`;
foreach $lines(@lines) {

# any white space and non white space
#
$lines =~ /\s+(\S+)$/;
$file = $1;
# checking for the file extension 
#
if ($file =~ /$file_ext$/) {

# assigning the path name with extension for o/p later
#
$file_name = $dir."/".$file;

# Open the file
#
open(elements, $file_name);

# read into an array		
@lines_in_file = <elements>;

# initiate the number of matched patterns to 0
#		
$count = 0;
foreach $strings (@strings) {
foreach $lines_in_file (@lines_in_file) {

# comparing the pattern required to the pattern available in file
#
if ($lines_in_file =~ /$strings/) {

#increment if the Number of strings matched
#
$count += 1;
last;
}
}
}

# close the file
#
close(elements);

# print if all the required patterns are matched
#
if ($count == 2) {
print "$file_name\n";
}
}
}
	
# search sub directories if any
@lines = `cd $dir; ls -l`;
foreach $lines (@lines) {
if($lines =~ /^d/) {
$lines =~ /\s+(\S+)$/;
$subdir = $dir."/".$1;
&search_directory($subdir);
}
}

}