Thursday, February 7, 2008

Learning Perl, 4th Edition Notes 0x3

Learning Perl, 4th Edition Notes 0x3 by DaNmarner * In Perl, a "function" indicates either a Perl build-in function or a user-defined function, while a "subroutine" means only the latter. * The defination of a subroutine includes a keyword "sub", followed by the function name and then the code block enclosed by curly braces. * To invoke a subroutine, use ampersand (&) before the function name. * Besides the use of "return", Perl automatically treats the last performed calculation as the return value. * Perl saves the parameters list in the private array @_, * Excess parameters as well as the insuffient ones, will be ignored. in the second case, undef will fill in the blank arguments. * All variables are defaulely globle unless the operator "my" is used. "my" makes a varable lexical. This works not only in functions but also in code blocks. * The "use strict" prama will force the declaration of every new variable to be coded. * If a subroutine is defined before its invocation, or it is invoked with arguments, and its name doesn't conficts with a build-in function, the ampersand can be omitted. * A "return" with nothing followed will make the subroutine return undef. * Not only scalars can be the return value.

No comments: