Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Perl module
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Packages and modules=== Conventionally, namespaces are associated with modules; in practice, there is usually one namespace per module and vice versa, but that's not mandated by the language. For example, the 'standard' module CGI.pm has the following declaration at its top: <syntaxhighlight lang="perl"> package CGI; </syntaxhighlight> This module, and its functionality, would commonly be invoked as follows: <syntaxhighlight lang="perl"> use CGI (':standard'); # imports many functions, including b() ... print b('Hello, world'); # outputs <b>Hello, world</b> </syntaxhighlight> A 'missing' subroutine ''could'' be added from the using program's namespace. <syntaxhighlight lang="perl"> sub CGI::bi { # define target namespace (CGI) and sub name (bi) return b(i($_[0])); } </syntaxhighlight> and invoked as below: <syntaxhighlight lang="perl"> print CGI::bi('Hello, world'); # outputs <b><i>Hello, world</i></b> </syntaxhighlight> However, though technically feasible, that would be dubious programming practice. You might just as well define the sub in the calling namespace, and call it from that namespace.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)