Use postfix ( Fixity) parentheses to invoke a named function. Any arguments to the function may go within the parentheses:
A function receives its parameters in a single array, @_ ( The Default Array Variables ). When you invoke a function, Perl flattens all provided arguments into a single list. The function must either unpack its parameters into variables or operate on @_ directly:
Every function has a containing namespace ( Packages ). Functions in an undeclared namespace—functions not declared within the scope of an explicit package statement—exist in the main namespace. You may also declare a function within another namespace by prefixing its name:
Use the caller builtin to inspect a function's calling context. When passed no arguments, caller returns a list containing the name of the calling package, the name of the file containing the call, and the line number of the file on which the call occurred:
Perl still supports old-style invocations of functions, carried over from ancient versions of Perl. Previous versions of Perl required you to invoke functions with a leading ampersand ( &) character:
Everything with a name in Perl (a variable, a function, a filehandle, a class) has a scope. This scope governs the lifespan and visibility of these entities. Scoping helps to enforce encapsulation —keeping related concepts together and preventing their details from leaking.
An anonymous function is a function without a name. It behaves exactly like a named function—you can invoke it, pass it arguments, return values from it, and take references to it. Yet you can only access an anonymous function by reference ( Function References ), not by name.