DocTaur - intranet directory of reference manuals
Yo-store
books for webmasters

reference manuals search engine

Perl Tutorial Book

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.1 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.


This document was generated on July, 31 2004 using texi2html 1.70.