in reply to Re: hash slice ? No thanks, I'm about to return...
in thread hash slice ? No thanks, I'm about to return...

Or just a "%return" - return is optional. Either way, make the return value explicit, rather than relying on a complex operation to do it, whether you make the fact you're returning explicit or not.

(I did some benchmarks a while back which surprised me to find out that "return %hash" was actually slower than "%hash" and falling out the bottom of the function...)

  • Comment on Re^2: hash slice ? No thanks, I'm about to return...

Replies are listed 'Best First'.
Re^3: hash slice ? No thanks, I'm about to return...
by lidden (Curate) on Feb 19, 2005 at 17:11 UTC
    You surprised me with this, but:
    Rate return no ret return 4682554/s -- -30% no ret 6642457/s 42% --
    Is what i got from:
    use Benchmark qw( cmpthese ); my %hash = (1, 2, 4, 6, 43, 32, 5, 6, 6, 43, 3, 54, 5, 1); cmpthese(0, { 'return' => sub { return \%hash }, 'no ret' => sub { \%hash }, });
      Surprising but pointless. Even the "slow" explicit return runs at 4 million iterations per second. Don't waste your time trying to use this as a real optimization.
Re^3: hash slice ? No thanks, I'm about to return...
by Aristotle (Chancellor) on Feb 19, 2005 at 16:59 UTC

    Depends. I often implicitly return the result of an operation that would obviously be useless in void context, as in

    sub as_string { my $self = shift; join '-', $self->date; }

    or the like.

    Makeshifts last the longest.