perlperl-module

Should I change my utilities.pl to a utilities.pm module?


In our product we have a big utilities file that we require (with do) at the beginning of a lot of our files. Is there a reason not to turn this into a module? For example, instead of doing this:

do '../dbi_utilities.pl';
our ($db,$user,$pw,$attr);
my $Data = DBI->connect($db,$user,$pw,$attr) or die "Could not connect to database: $DBI::errstr";

Couldn't I just do this?:

use AppUtil;
my $Data = AppUtil->connect();

Solution

  • The only reason not to do this is time.

    That is, it'll take time to clean up your interface, as well as all calling apps to use the new interface.

    What it'll cost you in time now will be more than made up when you start using proper tests ("make test" or "./Build test" or just "prove ...") and be able to check that your changes won't break anything before checking it in. So, by all means, convert. Just be aware that it's not a free gain.