I'm in the process of writing it, haven't compiled it yet and the thought came to me, there must be a way to compress this down such that I don't need to cut/paste/tweak the same 6 lines.
I personally believe that you should take those six lines and put them into a sub. Possibly put the sub into a module. I must admit that didn't follow the whole discussion because it looked like a mess, but this is a general purpose piece of advice that should apply to any situation in which you have the feeling you're copying and pasting too much.
| [reply] [d/l] |
naveed010,
Welcome to the Monastery and take some time to browse its sections. Particularly Tutorials.
Read How (Not) To Ask A Question. That will help you getting help from others.
As for the question itself, in my first reply I'm being honest (although it may not seem so) when I tell you to worry about making the code readable.
In that same response I showed a revised version of the code, it happens to have more lines but still I think it is more readable. Take a look at it.
And, surprise, it also answers the question you are now asking. The repeating parts are in a separate sub.
The second reply is, of course, a joke.
| [reply] |