[Melbourne-pm] Perl best practices: script actions based on a command line argument
daniel at rimspace.net
Thu Jan 31 21:41:48 PST 2008
I semi-regularly end up writing small scripts that do little jobs for
myself, such as performing various DNS checks, interfacing to billing
systems and the like.
Generally these end up as a single script that handles half a dozen
closely related but mostly independent functions, such as:
dns mx ... # check MX details for a domain
dns ns ... # check NS details for a domain
I typically implement this as a bunch of supporting code and libraries,
and a command wrapper that read the first command line argument and
dispatches to a function based on it.
This being Perl there are a lot of ways to do that, all of which are
a bit ugly (in my opinion), such as a cascade of if ($blah eq 'foo')
statements or a hash full of function refs...
So, what is the general consensus on the best way to do this -- what is
the nicest way to dispatch to the various command handlers based on a
command line argument?
Daniel Pittman <daniel at cybersource.com.au> Phone: 03 9428 6922
1/130-132 Stawell St, Richmond Web: http://www.cyber.com.au
Cybersource: Australia's Leading Linux and Open Source Solutions Company
More information about the Melbourne-pm