http://qs1969.pair.com?node_id=761785


in reply to Refactoring copy-pasted code

If possible, I'd break this into two tasks: Parsing the input file, and then processing the data. (I am assuming the intent is to do the same thing with all the files, just that the data format is slightly different.)

The end result I'd be aiming for is a script and several modules (one per data format, most likely). Then you run the script, have some way for it to figure out which parser to pass it to (either automatic or manual as a command-line switch), and have it then take back the data in some cannocial form (hash?) and do whatever you want.

(Note/Advertisement): If the data files are all line-oriented (that is: Each line can be read on it's own), my Mail::Log::Parse modules (which I'm working on generalizing, not that it needs much work) can do a lot of the heavy lifting of opening, buffering, seeking, and decompressing the files for you, leaving you to only writing one function for parsing per file format.)

Replies are listed 'Best First'.
Re^2: Refactoring copy-pasted code
by szabgab (Priest) on May 04, 2009 at 18:18 UTC
    I think there is a misunderstanding here.

    I am not looking for a solution to the how to collect data from various sources? problem.

    I am looking for an answer on how to locate duplicate code? and maybe how to unite duplicate code to a single copy?.