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"; }
In reply to Re: Re: Re: Command line tool coding style?
by perrin
in thread Command line tool coding style?
by Aristotle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |