[Melbourne-pm] Perl best practices: script actions based on acommand line argument
Leigh Sharpe
lsharpe at pacificwireless.com.au
Thu Jan 31 22:18:06 PST 2008
What about:
My $mode=shift;
$mode eq 'dns' and dns_function();
$mode eq 'mx' and mx_function();
# etc.
# etc.
It's a little less ugly than the cascading if..else's.
-----Original Message-----
From: melbourne-pm-bounces+lsharpe=pacificwireless.com.au at pm.org
[mailto:melbourne-pm-bounces+lsharpe=pacificwireless.com.au at pm.org] On
Behalf Of Daniel Pittman
Sent: Friday, 1 February 2008 4:42 PM
To: melbourne-pm at pm.org
Subject: [Melbourne-pm] Perl best practices: script actions based on
acommand line argument
G'day.
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?
Regards,
Daniel
--
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
_______________________________________________
Melbourne-pm mailing list
Melbourne-pm at pm.org
http://mail.pm.org/mailman/listinfo/melbourne-pm
More information about the Melbourne-pm
mailing list