#!/usr/local/bin/perl # search for a file in all subdirectories # $file_ext = '.cc'; # match for ' speech and any digit' # @strings = ('sum'); # look in current directory # $dir = "/cavs/hse/ies/d002/isip/users/pannuri/tools/class/"; 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); # 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 = ; # 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); } } } sub line_is_a_float_function { local($argument); if ($line_in_file =~ /^([a-zA-Z_]+\s+)+[a-zA-Z_:]+\((.*)$/) { $argument = $2; while ($argument =~ /.*^\)/) { ++$i; $line_in_file = $lines_in_file[$i]; $argument .= $line_in_file; } if ($argument =~ /F|float/) { return 1; } else { return 0; } } else { return 0; } }