I got confused with something while importing a module, like:
use POSIX;
&
use POSIX();
&
use POSIX qw(WNOHANG);
What is the difference between these use
?
Most modules use the Exporter
module to expose functions/variables/constants in the callee's namespace.
use POSIX;
This will only import all symbols from POSIX's @EXPORT
into the namespace of the calling module.
use POSIX();
This will not import any symbols into the calling namespace. It does however load the module, which means you can call functions like POSIX::strftime(...)
, etc.
use POSIX(WNOHANG)
This will only import the symbol WNOHANG
into the calling module's namespace.
If you are not familiar with the @EXPORT
and @EXPORT_OK
arrays, you should definitely run through the documentation of Exporter. Using Exporter
is the standard way in Perl to export symbols from one module into the namespace of your module (the calling namespace). POSIX
uses it as well.
It's also probably worth mentioning that modules designed with an object-oriented interface, generally do not require symbols to be imported.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With