In both versions of gen_fib, the closure unnecessarily re-calculates the last value of @fibs. For instance, if @fibs contains (0, 1, 1), then when called for fib(3) the closure calculates fib(2) then fib(3), then when called for fib(4) it calculates fib(3) then fib(4), etc. So in both versions this line:
for my $calc ((@fibs - 1) .. $item)
should be this:
for my $calc (@fibs .. $item)
Also, it's not necessary to initialise the cache with fib(2). Though doing so doesn't hurt the code, it's potentially confusing. So this:
my @fibs = (0, 1, 1);
my @fibs = (0, 1);
Good catch. Fixed in 0ed4d23. Thank you!
Improved gen_fib() (Grame Hewson, GH #166).