in reply to (tye)Re: Multiple Return Values
in thread Multiple Return Values

Re hash slice: thanks for pointing that out. It's much cleaner than mapcar. I also like how you did the internal vs supplied hash--I had pondered always using an inside one and assigning it to the dereferenced param, but thought that was gross.

It looks like your code is for returning things from a class, like what you can do with Tk widgets, right?

I'm thinking of something that naturally creates a list, like gmtime. I suppose if you had a time object instead, you wouldn't have the problem of returning 8 scalars in the first place.

—John

Replies are listed 'Best First'.
(tye)Re2: Multiple Return Values
by tye (Sage) on Jul 12, 2001 at 01:53 UTC

    Thanks. Yes, that example is OO. Here it is reworked non-OO:

    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}{@_}; }
    Note that these versions let you do interesting things like:
    my $year= LocalTime( time(), \(my %time), qw( second minute hour day month year ) );

            - tye (but my friends call me "Tye")