in reply to Re^2: Command line tool coding style?
in thread Command line tool coding style?
You can easilly get by strict if you use this:
It might be good to check the text of the exception here to make sure it's from a missing sub. You might even be able to do this:eval('&' . $action . '()'); if( $@ ) { die "Usage\n"; }
I haven't tried that last though.my $subref = \&{$action}; die "Usage" unless defined &$subref();
There's just no good reason to use OO here, and it makes the code more confusing and JAPH-ish. Maybe there's something else in your program that justifies OO, but this problem doesn't.
Incidentally, a nicer way to write that dispatch table from your above comment would be something like this (untested):
my %dispatch = ( 'this' => \&do_this, 'that' => \&do_that, ); if (defined $dispatch{$action}) { &$dispatch{$action}; } else { die "Usage\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Command line tool coding style?
by Aristotle (Chancellor) on Jan 16, 2002 at 17:40 UTC | |
by perrin (Chancellor) on Jan 16, 2002 at 23:10 UTC | |
by Aristotle (Chancellor) on Jan 17, 2002 at 02:40 UTC |
In Section
Seekers of Perl Wisdom