Lesson 48 of 55
9 mins readPython Packages, Modules & the 1; Convention
In Plain English
Perl namespaces are defined with `package PackageName;`. Modules are saved in `.pm` files and must end with a true return value (`1;`). Load them with `use Module;`.
Deep Dive: How It Works
package Namespace: Encloses variables and subroutines in a distinct namespace (e.g. `Math::Utils`).
The 1; Convention: Every `.pm` module file must evaluate to true at the bottom to signal successful compilation to the interpreter.
use vs require: `use` loads and compiles modules at compile-time; `require` loads at runtime.
@INC Array: List of directory paths Perl searches when locating modules.
Core Rules to Remember

Namespaces with package: Separates function names to avoid global pollution.

Mandatory 1; at End of File: Every Perl module must terminate with `1;`.
Live Interactive Example
Hit Run Code to see it liveDefining and Calling Namespaced Subroutines
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Output Console
Click "Run Code" to view the rendered output.
How it works: Logger::log_info called the subroutine defined within the Logger package namespace.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Call Namespaced Subroutine
Define `package MathUtils { sub square { my $n = shift; return $n * $n; } }`
In `package main;`, print `"Square: " . MathUtils::square(9) . "\n"`.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.