The code I use looks like this:
except that %opts actually contains references to "get" methods.my @opts= qw( This That TheOther Else Foo Bar Blatz ); my %opts; @opts{@opts}= 1x@opts; sub GetOptions { my $self= shift(@_); my $href= {}; $href= shift(@_) if @_ && UNIVERSAL::isa($_[0],"HASH"); @_= @opts if ! @_; foreach my $opt ( @_ ) { croak ref($self),"->GetOptions: Invalid option ($opt) ", "not one of ( @opts )" unless $opts{$opt}; $href->{$opt}= $self->Get($opt); } return @{$href}{@_}; }
For your helper code I suggest this change:
or just use a hash slice directly in the caller. - tye (but my friends call me "Tye")sub _populate_hash { my $hvHash= shift(@_); my $avValues= shift(@_); my $avNames= shift(@_); croak unless @$avValues == @$avNames; @{$hvHash}{@$avNames}= @$avValues; }
In reply to (tye)Re: Multiple Return Values
by tye
in thread Multiple Return Values
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |