Subroutines or functions
When writing subroutines, if you do the following,
sub myfunc()
{
my($a1,$a2,$a3) = @_;
return $a1 . $a2 . $a3;
}
print(myfunc("this","is","a test"));
it will give you an error - something like too many arguments.
What's happening is if you start your subroutine with myfunc(), meaning you have parentheses, you are saying this function takes no arguments, so the too many arguments error makes sense. You should actually write the above as,
sub myfunc
{
my($a1,$a2,$a3) = @_;
return $a1 . $a2 . $a3;
}
print(myfunc("this","is","a test"));
[Click to add or edit comments])
Please prepend comments below including a date