Perl - Define a Function - sub
by Geethalakshmi[ Edit ] 2010-09-17 14:15:49
Perl - Define a Function - sub
Functions work like subroutines. They can appear anywhere with the code and are only executed when called. The normal program flow will skip over subroutines. The standard method is to place them at the end of the code. All variables used within the subroutine are global unless otherwise specified. A subroutine is identified by the word 'sub', followed by the name of the subroutine. The folowing code associated with the sub must be surrounded by '{ }'s.
sub subname {
statement1;
statement2;
}