in reply to Re: (tye)Re: Multiple Return Values
in thread Multiple Return Values
Thanks. Yes, that example is OO. Here it is reworked non-OO:
Note that these versions let you do interesting things like:my @opts= qw( second minute hour day month year weekday yearday isdst ); my %opts; @opts{@opts}= 0..$#opts; sub LocalTime { my $time= shift(@_); my @values= localtime($time); return @values if ! @_; # Optional but may save CPU (: my $href= {}; $href= shift(@_) if @_ && UNIVERSAL::isa($_[0],"HASH"); @_= @opts if ! @_; foreach my $opt ( @_ ) { croak "LocalTime: Invalid option ($opt) not one of ", "( @opts )" unless defined $opts{$opt}; $href->{$opt}= $values[$opts{$opt}]; } return @{$href}{@_}; }
- tye (but my friends call me "Tye")my $year= LocalTime( time(), \(my %time), qw( second minute hour day month year ) );
|
|---|