Subroutines in Perl are declared as follows...
sub sayhello
{
print "Hello";
}
/* calls to a subroutine */
sayhello
();
&sayhello
();
When you want to call (execute) a subroutine, there are two ways you may do so...
- Call the name of the subroutine as-is.
- Call the name of the subroutine, with an ampersand in the front.
Our recommendation? Get in the habit of using the ampersand.
- It will make your subroutines easier to spot.
- It will let you call the subroutine before you actually declare it. Calls to subroutines without the ampersand will result in an error message if they occur before the subroutine has been declared.
There are no comments on this page. [Add comment]