InMotion Web Site Hosting
InMotion Hosting Home




Node:Defining Subroutines, Next:, Previous:Subroutines, Up:Subroutines



Defining Subroutines

Defining a subroutine is quite easy. You use the keyword sub, followed by the name of your subroutine, followed by a code block. This friendly subroutine can be used to greet the user:

use strict;
sub HowdyEveryone {
   print "Hello everyone.\nWhere do you want to go with Perl today?\n";
}

Now, anywhere in the code where we want to greet the user, we can simply say:

&HowdyEveryone;
and it will print that message to the user. In fact, in most cases, the & for invoking subroutines is optional.

InMotion Web Hosting Customer Support
M-F 8am - 7pm PST
213-239-0050

More information can be found at the InMotion Hosting Main Site