Ben Godfrey

FIBSEQ — Perl

#   Display n numbers from the Fibonacci sequence.
#
#   Afternoon <noon at aftnn.org>, 2004

sub fibseq {
    my ($n, $l) = @_;

    # if input is just a number, create the first two sequence numbers
    if (!defined($l)) { return fibseq($n - 2, [(1, 1)]); }

    # create the next sequence number
    push @{$l}, $l->[$#l - 1] + $l->[$#l];

    if ($n == 1) { return $l; }
    else { return fibseq($n - 1, $l); }
}

print join(", ", @{fibseq($ARGV[0])}), "\n";