perl_mystery has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Help regarding an alogrithm
by wind (Priest) on Mar 18, 2011 at 06:18 UTC

      Well he did say, "I have tried various ways to achieve this..."

      From what I see, this means, he's tried posting to perlmonks a couple times now, AND other forums. That's "various".

Re: Help regarding an alogrithm
by samarzone (Pilgrim) on Mar 18, 2011 at 06:13 UTC
    1. Read file "data.txt" line by line. Every line has name of a directory.
    2. Find all the *.c files in current directory and run a loop on these files
    3. Inside above loop read every line of current (*.c) file and run a regular expression to match "modem" case-insensitively with word boundary.
    4. If any of the match (in case of multiple matches) is not equal to (eq) "modem" print the line and file (*.c) name

    I hope this helps

    --
    Regards
    - Samar

      At step #3,for every file I open,I need to search for all the contents present in data.txt ,not only modem,basically for every .c I have to check if any of the dir names in data.txt are present,how do I match that ?am already in a for loop opening each and every .c files

        Read the contents of "data.txt" in an array and run a loop on the array as step#1. This way you have all the directory names with you in the array, at the step #3. Run step #3 and #4 for all the names in array instead of just "modem"

        --
        Regards
        - Samar
Re: Help regarding an alogrithm
by JavaFan (Canon) on Mar 18, 2011 at 11:26 UTC
    Perl? Overkill.

    Something like (untested, may need tweaking) should do:

    $ find `cat data.txt` -name '*.c' -print0 | -xargs -0 grep -i modem
Re: Help regarding an alogrithm
by apl (Monsignor) on Mar 18, 2011 at 10:44 UTC
    Write down, in the human language you're most comfortable in, how you would explain to a 10 year old how to solve this problem. Translating that into Perl is simple.
Re: Help regarding an alogrithm
by Anonymous Monk on Mar 18, 2011 at 07:11 UTC
    I have tried various ways to achieve this with but no luck,vexed of it.I

    Prove it