#! /usr/bin/perl use strict; use warnings; sub fac { my $n = $_[0]; #注意此處,也能夠寫my $n = shift()或者是my ($n) = @_; if(1 == $n) { return 1; } else { return ($n * fac($n - 1)); } } print "Please input a number:"; chomp (my $n = <STDIN>); #請注意此處n的範圍。 my $result = fac($n); print "$n! = $result\n";