in reply to Re: Structuring code
in thread Structuring code
Hi scooterm, thanks for the suggestions (and example code). You are correct - there really isn't any reason why I can't use a simple hash lookup table for this data (which is how I have it structured now, although it is a HoH instead), so perhaps I am trying to over-engineer things a bit.
The example you gave (based on the OP) essentially follows the same process for each type:
In my case most of the code blocks are the same, so process {dir} is the same code for all types (the only difference between them is the value of {dir}, which can be passed as a parameter). There are some instances where the code itself varies, however, which is why I have regexes as part of the data structure. More specifically, I do stuff like this:# determine type # process {dir} # process {text1} # munge munge munge...
which allows me to use the same function to readdir and grep without having a nearly identical copy of it for each $type.my @files = get_filenames( $data{$type}{dir}, $data{$type}{regex} );
I guess what it comes down to is that I'm trying to balance minimizing code redundancy with over-generalizing (and therefore over-parameterizing) things. I found myself going in circles about how to design this, so I decided it was time to consult the Monks. Sometimes simple is better than fancy. Thanks for the reality check.
|
|---|