my $opts = GetOptions (
"input|source|i:s" => sub { if(@_[1]) {
$new->source(@_[1]);
}else{
$new->source($last->source);
} },
"verbose" => sub { $new->verbose(@_[1]); },
# and so on
What I find ugly is the use of @_[1] to reference the value that GetOptions parses for each option. @_[0] is the option name. @_[1,2] are used for values or references to hashes and lists.
I suppose I could just pass the whole list to the object method, but that gets ugly since most of these methods are designed to store/retrieve attributes and defined by an AUTOLOAD subroutine down in the class i.e. package.
First, turn on warnings and behold what happens. What you're doing works, but is not proper. Change all occurrences of @_[1] to $_[1] (and so on).
Also, with constants you could name the subscripts instead. Example:
use constant OPTION_NAME => 0;
sub { if( $_[OPTION_NAME] ) { .......
Dave
perlmonks.org content © perlmonks.org and davido, perlcapt
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03