Perl module: Difference between revisions

Content deleted Content added
Perl packages and namespaces: Clarified terminology in comments in examples; improved formatting
Procedural Example: Amplified comments in module definition
Line 43:
----
<source lang="perl">
# "package" givesis the namespace where the module's will reside infunctionality/data andresides. also
# It dictates the name of the file if you want it to be "use"d.
# If more than one word, it constrains the ___location of the module.
package Hello::World;
Line 50 ⟶ 51:
# By default Perl allows you to use variables without declaring
# them. While thisThis may be convenient for short scripts and one-liners.
# one-liners,But in a longer unit of code such as a module it is wise to declare your variables
# your variables both to catch typos and to keep them from beingconstrain accessibletheir outside
# accessibility appropriately from outside the module. The strict pragma
# forces you to declare your variables.
use strict;
# Similarly, Perl does not issue warningsmost bycompiler default.or run-time Awarnings module,by beingdefault.
# moreMore complicated thanscripts, asuch script,as usuallymost modules, will usually find them very helpful
# helpful for debugging. The warnings pragma turns on optional warnings.
use warnings;
Line 73 ⟶ 75:
use base 'Exporter';
# ExportWhen the module is invoked, export, by default, the function "hello" into the namespace of
# anythe codenamespace whichof usesthe thisusing modulecode.
our @EXPORT = qw(hello);
Line 95 ⟶ 97:
This is a procedural module which gives you the famous "Hello, world!"
message, and itsit’s even customizable!
=head2 Functions