in reply to How am i doing?

I tryed all the suggestions however it has started producing a warning of: "Use of uninitialized value $frame1 in addition (+) at ./eul2.pl line 13." I have decided to change to a parameter map with values a, b, c like it suggests in the book. If it has the warning is it only that line that has the problem, or is it like java errors where it "snow balls" that is what I was used to in previous coding experience. Heres the new version I was suprised how perl compiles when I wasn't as confident that it would.
#!/usr/bin/perl use v5.14; use strict; use warnings; my $result = 0; sub fib { my @frame = @_; $frame[0] += $frame[1]; $frame[1] = $frame[2]; $frame[2] = $frame[3]; count($frame[0]); return fib(@frame) unless($frame[0] >= 4_000_000); } sub count { my $increment = shift; if(($increment % 2) == 0) { $result += $increment; } } fib(1,2,3); say $result;

Replies are listed 'Best First'.
Re^2: How am i doing?
by ikegami (Patriarch) on Jul 17, 2025 at 20:55 UTC

    You still pass 1, 2, 3 to the first call (instead of 0, 1)

    More importantly, you still pass $frame[0]+$frame[1], $frame[2], $frame[3] to the subsequent calls . That's completely wrong. You need to pass the nth and (n+1)th terms.