in reply to inline caching a list-generating sub
Wait...if you just want to fix scalar context,sub foo { ($foo_cache{...} ||= do { my @result = do { ... rest of sub goes here } sub { @result[0..$#result] }; }; )->(); }
Would there be more to a list keyword than this?my %foo_cache; sub foo { my $index = join ",", @_; $foo_cache{$index} ||= do { .... }; wantarray ? @{$foo_cache{$index} : $foo_cache{$index}[-1]; }
sub list { wantarray ? @_ : $_[-1]; }
|
|---|