Perlsub

PERLSUB(1) Perl Programmers Reference Guide PERLSUB(1)

Perlsub

PERLSUB(1) Perl Programmers Reference Guide PERLSUB(1) # PERLSUB(1) Perl Programmers Reference Guide PERLSUB(1) NNAAMMEE # perlsub - Perl subroutines SSYYNNOOPPSSIISS # To declare subroutines: sub NAME; # A "forward" declaration. sub NAME(PROTO); # ditto, but with prototypes sub NAME : ATTRS; # with attributes sub NAME(PROTO) : ATTRS; # with attributes and prototypes sub NAME BLOCK # A declaration and a definition. sub NAME(PROTO) BLOCK # ditto, but with prototypes sub NAME : ATTRS BLOCK # with attributes sub NAME(PROTO) : ATTRS BLOCK # with prototypes and attributes use feature 'signatures'; sub NAME(SIG) BLOCK # with signature sub NAME :ATTRS (SIG) BLOCK # with signature, attributes sub NAME :prototype(PROTO) (SIG) BLOCK # with signature, prototype To define an anonymous subroutine at runtime: $subref = sub BLOCK; # no proto $subref = sub (PROTO) BLOCK; # with proto $subref = sub : ATTRS BLOCK; # with attributes $subref = sub (PROTO) : ATTRS BLOCK; # with proto and attributes use feature 'signatures'; $subref = sub (SIG) BLOCK; # with signature $subref = sub : ATTRS(SIG) BLOCK; # with signature, attributes To import subroutines: use MODULE qw(NAME1 NAME2 NAME3); To call subroutines: NAME(LIST); # & is optional with parentheses. ...