#!/bin/perl -w use strict; use File::Find; use Time::localtime; use Data::Dumper; package main; ##################################################################### # final_search.pl - the miracle of searching & printing source path, # filename, and source code line where used. # # If you don't provide a directory path on the command line, # it will default to the current directory. # ##################################################################### my @Constants = ( "fee", "fie", "foe", "fum" ); my $day_of_year = localtime(time())->yday; my $year = localtime(time())->year + 1900; my $path = $ARGV[0] || "."; # use the current directory or supplied path my $count = 0; my $fname1 = ""; my $fname2 = ""; my $line = ""; my $search_string = ""; print "\n <<<<< Constants Search Script >>>>> \n\n"; print " >>> Today is the $day_of_year 'th day of $year <<< \n\n"; sub wanted { my $fname1 = $File::Find::name; return unless $fname1 =~ /\.[ch]$/; push(@files, $fname1); } find(\&wanted, $path); # print Dumper(\@files); # Uncomment to check out the array for $fname2 (@files) { open (INFILE, "$fname2") or warn "can't open file: $fname2 : $! "; while () { $line = $_; for $search_string (@Constants) { if ($line =~ /\b$search_string\b/) { # print the path/filename:line number - the code line print "$fname2:$. - $line \n"; } } } close (INFILE); ++$count; } print "\n <<<>>> Searched $count files <<<>>> \n"; print "\n"; # END - package main