Chapter 5. Subroutines

     

Subroutines are reusable units of code. They can be called from just about anywhere , and return control to the point of the call when they finish executing. They can be passed zero or more arguments [1] and return zero or more results. Subroutines can be named or anonymous. They can be lexically scoped, package scoped, or globally scoped. "Multi" subs allow multiple subroutines to have the same name as long as they have different parameter lists.

[1] Following the example set in Apocalypse 6, throughout this chapter we'll use the term "argument" for the values passed into a subroutine call and "parameter" for the lexical variables declared in the subroutine's signature.

Methods are significantly different from subroutines. In Perl 6, they're even distinguished by a separate keyword, method . These differences will be discussed in Chapter 6.



Perl 6 and Parrot Essentials
Perl 6 and Parrot Essentials, Second Edition
ISBN: 059600737X
EAN: 2147483647
Year: 2003
Pages: 116

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net