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

Hi, While going through some code of mine, i realised that i've used fair amount of hardcoded variables intentionally/unintentionally. I am aware that it is a bad way to script. I am trying to identify all the hardcoded variables. Please can anyone let me know if there's an easier way to hunt these down rather than bore holes into the script scanning every line of code? Thanks in Advance!

Replies are listed 'Best First'.
Re: Searching hardcoded variables
by CountZero (Bishop) on Jan 16, 2009 at 12:50 UTC
    What do you mean by "hardcoded variables"? Can you give us an example?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Im sorry , i guess my question was ambiguous. What im trying to do is replace all the hardcoded material with variables. egs : my $_out = `tcpreplay -i eth0 pkt_dump`; i want to re-wrtie it as : my $_cmd = "tcpreplay -i eth0 " ; my $_out = `$_cmd pkt_dump`; In effect , i want to replace all the hardcodes with variables in a lot many places.
        If all your hardcoded data is coming from an external program, then you can just search for the back-quotes. You can even write a Perl-program to do so and (if all hardcoded material follows the same format) replace it by your variables.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Searching hardcoded variables
by JavaFan (Canon) on Jan 16, 2009 at 12:47 UTC
    overload::constant