#!/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 (<INFILE>) { $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

In reply to Utility for Finding Constants hidden in 'C' Source Code by pmonk4ever

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.