Perl module: Difference between revisions

Content deleted Content added
Procedural Example: Amplified comments in module definition
Packages and modules: Add comments in invocation example; amplified commentary
Line 321:
This module, and its functionality, would commonly be invoked as follows:
<source lang="perl">
use CGI (':standard'); # imports many functions, including b()
...
print b('Hello, world'); # outputs <b>Hello, world</b>
Line 327:
A 'missing' subroutine ''could'' be added from the using program's namespace.
<source lang="perl">
sub CGI::bi { # define target namespace (CGI) and sub name (bi)
return b(i($_[0]));
}
Line 335:
print CGI::bi('Hello, world'); # outputs <b><i>Hello, world</i></b>
</source>
However, though technically feasible, that would be somewhat dubious programming practice. You might just as well define the sub in the calling namespace, and call it from that namespace.
 
However, though technically feasible, that would be somewhat dubious programming practice.
 
== Further reading ==