Section B.8. Chapter 9, Subroutines


B.8. Chapter 9, Subroutines

  • Call subroutines with parentheses but without a leading &. [Call Syntax]

  • Don't give subroutines the same names as built-in functions. [Homonyms]

  • Always unpack @_ first. [Argument Lists]

  • Use a hash of named arguments for any subroutine that has more than three parameters. [Named Arguments]

  • Use definedness or existence to test for missing arguments. [Missing Arguments]

  • Resolve any default argument values as soon as @_ is unpacked. [Default Argument Values]

  • Always return scalar in scalar returns. [Scalar Return Values]

  • Make list-returning subroutines return the "obvious" value in scalar context. [Contextual Return Values]

  • When there is no "obvious" scalar context return value, consider Contextual::Return instead. [Multi-Contextual Return Values]

  • Don't use subroutine prototypes. [Prototypes]

  • Always return via an explicit return. [Implicit Returns]

  • Use a bare return to return failure. [Returning Failure]



Perl Best Practices
Perl Best Practices
ISBN: 0596001738
EAN: 2147483647
Year: 2004
Pages: 350
Authors: Damian Conway

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