Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

[ < ] [ > ]   [ << ] [ 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.




 
 
  Published under the terms of the GNU General Public License Design by Interspire