I need to search the source file directories for all *.c & *.h which are using any of 4 constants which are defined in a @Constants list.

Then spit out the path, filename, and the source lines where used, as they are found, to the screen. I can use tee to display to CRT & log into a file if needed later.

The OS is SGI Unix, PERL 5.6.1

I have pulled together a couple of subs, one which will search a single file for the constants, the other to print the source line to the CRT.

I have looked thru the Q & A & the CPAN examples, but was unable to find anything like this. I will be happy to post the final solution for others learn from as well.

I thought this could all be written in Perl, but I just can't seem to get this script started. Can anyone help with an example of what I want?

Thanks in advance.

ki6jux

The examples for Find::File are a bit sparse, are there any other code snippets around?

I got the shell answer to work, but I'd still like to solution this in Perl, for the experience, as a test developer, I don't get to code as much as I'd like to!

ki6

UPDATE

Thank you my fellow Monks for your quick responses! I have reached a dual solution, one in 'C' Shell, and a very elegant one in Perl, which I shall post for fellow Monks to observe and learn ...

You have renewed my faith in my fellow man/woman! Thank you!

ki6jux


In reply to Search thru directories of .c & .h files for @Constants 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.