Copyright © tutorialspoint.com

# PERL sub Function

## Syntax

    sub NAME PROTO ATTRS BLOCK# Named, prototype, attributes, definition
    sub NAME ATTRS BLOCK # Named, attributes, definition
    sub NAME PROTO BLOCK # Named, prototype, definition
    sub NAME BLOCK # Named, definition
    sub NAME PROTO ATTRS # Named, prototype, attributes
    sub NAME ATTRS # Named, attributes
    sub NAME PROTO # Named, prototype
    sub NAME # Named
    sub PROTO ATTRS BLOCK # Anonymous, prototype, attributes, definition
    sub ATTRS BLOCK # Anonymous, attributes, definition
    sub PROTO BLOCK # Anonymous, prototype, definition
    sub BLOCK # Anonymous, definition

## Definition and Usage

The sub keyword defines a new subroutine. The arguments shown above follow these rules:

- NAME is the name of the subroutine. Named subroutines can be predeclared (without an associated code block) with, or without, prototype specifications.

- Anonymous subroutines must have a definition.

- PROTO defines the prototype for a function, which will be used when the function is called to validate the supplied arguments.

- ATTRS define additional information for the parser about the subroutine being declared.

## Return Value

- Nothing

Copyright © tutorialspoint.com