I am working on a factorial function in Perl.
The code below gives me the error Can't return outside a subroutine.
factorial {
my $n = $ARGV[0];
if( $n <= 1 ){
return 1; # ----- Error Here -----
}
else {
return $n * factorial($n - 1);
}
}
I believe my if statement is still inside the subroutine. What is causing the error?