Fibonacci in Perl

Published on 28 April 2022 (Updated: 25 September 2022)

Fibonacci in Perl

Welcome to the Fibonacci in Perl page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

#!/usr/bin/perl
$num_args = $#ARGV + 1;
if ($num_args == 0) {
    print "Usage: please input the count of fibonacci numbers to output\n";
} elsif ($num_args == 1) {
    if ($ARGV[0] =~ /[0-9]+/) {
    	$n = $ARGV[0];
	$result = 0,$first = 0,$second = 1;
	for ($i = 1;$i <= $n;$i = $i + 1) {
	    $result = $first + $second;
	    $first = $second;
	    $second = $result;
	    print "$i: $first\n";
    	}
    } else {
        print "Usage: please input the count of fibonacci numbers to output\n";    
    }
} else {
    print "Usage: please input the count of fibonacci numbers to output\n";	
}

Fibonacci in Perl was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.