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