in reply to Parse for a name after a keyword search in all the files, given directory as input

Kindly let me know where am I going wrong!!

Unfortunately you have not said how it is going wrong and since we don't have your tree of files to run it on it's all down to guesswork. See SSCCE. "It doesn't work" is as useful to a developer as "I'm ill" is to a medic. Be specific.

Also, the lack of strict and warnings is a bad sign. See the Basic Debugging Checklist.

Best guess is that your regex is wrong. Is the exact string you wish to find " ^module " with all that whitespace and the caret?

  • Comment on Re: Parse for a name after a keyword search in all the files, given directory as input

Replies are listed 'Best First'.
Re^2: Parse for a name after a keyword search in all the files, given directory as input
by prash_sri (Initiate) on Feb 17, 2017 at 08:51 UTC

    What I intend to do is, There is a directory, consisting of 10 files in .v format; I feed in the path for directory in command line and my code has to open all the files in the directory, and look for the word modulekeyword present at the starting of any line in the entire file for all the 10 files, and it should print the word next to moduleconsidered as keyword one in each line. As my .v file has multiple 'module' keywords.

    Ex : file.v
    Line No.2> module GATES(clock,variable); .... .... Line No.100> module FF(op, ip,);

    Output expected- GATES in 1st line FF in 2nd line

      So now we know in a little more detail what you want your script to do. Unfortunately you still have not said in what way it is going wrong.

      Here then are a few suggestions.

      1. Read, understand and implement at least the first 2 steps of the Basic Debugging Checklist. Do this now, before anything else.
      2. Test to see if you are actually looping over all files in the directory. At the very least print a count of all the files you have tested by the end of the script.
      3. Test your regex (which we now know is wrong). A simple perlish grep will do: perl -ne '/^module / and print' somedir/filename.v and then modify the regex until it extracts what you want.
      4. If you still can't get the required output then post back here stating precisely in what way your code fails and providing an SSCCE

      Happy debugging!