Name

sub

Synopsis

sub name [proto] {block}
sub [proto] name
                  

Declares and defines a subroutine. name is the name given to the subroutine; block is the code that will be executed when the subroutine is called. Without block, this statement declares only a subroutine, which must be defined at a later point in your program. proto is a sequence of symbols that places constraints on the arguments that the subroutine will receive. See Section 4.7.

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.