June 2005
Beginner
480 pages
10h 31m
English
You create user-defined subroutines in Perl by using the following syntax:
sub subroutine_name { statement1; : statementx; }
Subroutine names in Perl follow the same naming conventions as scalars, arrays, and hashes outlined in Hour 2, “Perl's Building Blocks: Numbers and Strings.” Subroutine names can have the same names as existing variables. However, you should avoid creating subroutine names that are the same as those of Perl's built-in functions and operators. Creating two subroutines with the same name in Perl causes Perl to emit a warning if warnings are enabled; otherwise, the second definition causes the first to be forgotten.
Here is an example of a subroutine:
sub countdown { for ($i=10; $i>=0; $i--) ...Read now
Unlock full access