Webmaster in a Nutshell

Previous Chapter 15
Perl Quick Reference
Next
 

15.6 Subroutines, Packages, and Modules

&subroutine list

Executes a subroutine declared by a sub declaration, and returns the value of the last expression evaluated in subroutine. subroutine can be an expression yielding a reference to a code object. The & may be omitted if the subroutine has been declared before being used.

bless ref [ , package ]

Turns the object ref into an object in package. Returns the reference.

caller [ expr ]

Returns an array ($package, $file, $line,...) for a specific subroutine call. caller returns this information for the current subroutine, caller(1) for the caller of this subroutine, etc. Returns false if no caller.

do subroutine list

Deprecated form of &subroutine .

goto &subroutine

Substitutes a call to subroutine for the current subroutine.

import module [ [ version ] list ]

Imports the named subroutines from module.

no module [ list ]

Cancels imported semantics. See use.

package name

Designates the remainder of the current block as a package.

require expr(dagger)

If expr is numeric, requires Perl to be at least that version. Otherwise expr must be the name of a file that is included from the Perl library. Does not include more than once, and yields a fatal error if the file does not evaluate to a true value. If expr is a bare word, assumes extension .pm for the name of the file.

return expr

Returns from a subroutine with the value specified.

sub name { expr ;...}

Designates name as a subroutine. Parameters are passed by reference as array @_. Returns the value of the last expression evaluated.

[ sub ] BEGIN { expr ; ...}

Defines a setup block to be called before execution.

[ sub ] END { expr ; ...}

Defines a cleanup block to be called upon termination.

tie var, package, [ list ]

Ties a variable to a package that will handle it. Can be used to bind a dbm or ndbm file to a hash.

untie var

Breaks the binding between the variable and the package.

use module [ [ version ] list ]

Imports semantics from the named module into the current package.


Previous Home Next
Statements Book Index Object-Oriented Programming

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell
Hosted by uCoz