in reply to Of strict, globals, packages and style
Second off, you say "my scripts pretty much do the same thing". Then, you very nicely list each one and ask "Does it make sense to build a genric script ...?"
My answer to that question is "No." You don't want to build a generic script, you want to build a general-purpose library. For example, you always set up an ftp connection first. Ok, create a connect_ftp() function and house it in some library.
Why do it that way? Well, there's a lot of reasons. The biggest reason from a software engineering standpoint is testability of your library. You will want to verify that each piece works correctly on its own. You can't do that without a well-defined interface. But, for these little scripty-doos, you may not have the time for all that jazz.
The most important reason for you is that you will be asked to write a quick one-off script to do something just like what your generic script would do, but ever so slightly different. Maybe, it needs to process files that have already been downloaded. Or, you might want to run the file processing without the DB connection. Or, you want to create a report from the DB. I don't know and, more importantly, neither do you. If you have all your different actions in a tinker-toy/lego type of setup, it becomes easy to write that one-off script.
So, here's what I'd recommend:
package Useful::Stuff; use 5.6.0; use strict; use warnings; our $VERSION = 0.01; use base 'Exporter'; our @EXPORT_OK = qw( connect_ftp ); sub connect_ftp { } 1; __END__ =head1 NAME =cut
Please ask if you want more information on any point above or if you have questions about what you're doing. :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Of strict, globals, packages and style
by sauoq (Abbot) on Oct 20, 2005 at 20:06 UTC |