Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/perl
- #factorials from standard input
- sub factorial{
- if(@_ != 1){
- print "Warning! More/Less than one parameter to the factorial subroutine";
- }
- if ($_[0] == 1) {
- return 1;# force a return to go back up the stack
- }
- $_[0] * factorial($_[0]-1);# no need for the return keyword, last thing done so at the top of the stack
- }
- while (<>) {
- chomp;
- $factorialn = &factorial($_);
- print "Factorial " . $_ . " or " . $_ . "! is equal to " . $factorialn . "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement