Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Refactoring copy-pasted code

by DStaal (Chaplain)
on May 04, 2009 at 18:01 UTC ( #761785=note: print w/replies, xml ) Need Help??

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?.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://761785]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2023-06-05 20:35 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (26 votes). Check out past polls.