To use a module in your code, use the keyword use.
An example. Let us first create the module Greet and save it in the file named Greet.pm.
unit module Greet;ย sub hey($name) is export { ย ย ย say "Hey, $name!"; }
Then, let us use this module in our programme by saying use Greet.
use Greet;ย hey("you"); # Hey, you!
Module names can be more complicated. With is export, all the exported names will be available in the current scope after the module is used.
In the following example, the module Greet::Polite sits in the Greet/Polite.pm file.
module Greet::Polite { ย ย ย sub hello($name) is export { ย ย ย ย ย ย ย say "Hello, $name!"; ย ย ย } }
The programme uses both of these modules and can access all the exported subs.
use Greet; use Greet::Polite;ย hey("you");ย ย ย ย # a sub from Greet hello("Mr. X"); # from Greet::Polite