How to pass common arguments to Perl modules

Posted by Leonard on Stack Overflow See other posts from Stack Overflow or by Leonard
Published on 2010-05-03T19:22:04Z Indexed on 2010/05/03 19:28 UTC
Read the original article Hit count: 205

Filed under:
|

I'm not thrilled with the argument-passing architecture I'm evolving for the (many) Perl scripts that have been developed for some scripts that call various Hadoop MapReduce jobs.

There are currently 8 scripts (of the form run_something.pl) that are run from cron. (And more on the way ... we expect anywhere from 1 to 3 more for every function we add to hadoop.) Each of these have about 6 identical command-line parameters, and a couple command line parameters that are similar, all specified with Euclid.

The implementations are in a dozen .pm modules. Some of which are common, and others of which are unique....

Currently I'm passing the args globally to each module ...

Inside run_something.pl I have:

set_common_args         (%ARGV);
set_something_args      (%ARGV);

And inside Something.pm I have

sub set_something_args { (%MYARGS) =@_; }

So then I can do

if ( $MYARGS{'--needs_more_beer'} ) { 
    $beer++;
}

I'm seeing that I'm probably going to have additional "common" files that I'll want to pass args to, so I'll have three or four set_xxx_args calls at the top of each run_something.pl, and it just doesn't seem too elegant.

On the other hand, it beats passing the whole stupid argument array down the call chain, and choosing and passing individual elements down the call chain is (a) too much work (b) error-prone (c) doesn't buy much.

In lots of ways what I'm doing is just object-oriented design without the object-oriented language trappings, and it looks uglier without said trappings, but nonetheless ...

Anyone have thoughts or ideas?

© Stack Overflow or respective owner

Related posts about perl

Related posts about modules