in reply to Perl Module Useage

I have 2 general rules of thumb.

First: If I need to use a bit of code in more than 1 place, I take that time, instead of a cut/paste, to make it into a sub and change the existing bit of code to call the sub and the new bit of code becomes a call to the same sub.

There are times when the sub needs to be made a bit more generalized and I handle this at that time also.

Second: If I want to use that sub in another script I build that sub into a module which I can then import the function.

At the same time, if it makes sense I try to make the sub into an OO type of interface so I don't need to import the functions into my scripts unless it really makes sense to do it that way.

My experience is that if this overhead is done when there is only 1 existing piece of code which requires changing to use the new interface (sub {} or use Module;) then it is quick and easy to have these nice interfaces so that next time I want this functionality I just type use Module; my $thing=Module->new(...);, or use Module qw( my_keen_sub );

This has a really low cost in the short term and a huge win in the medium to long term, especially if I add a bit of pod to the sub and then a bit more when it gets into a module.