Perl Module Lists

I was confused by something while importing the module, for example:

use POSIX; 

&

 use POSIX(); 

&

 use POSIX qw(WNOHANG); 

What is the difference between these use ?

+6
source share
1 answer

Most modules use the Exporter module to display functions / variables / constants in the namespace of the called persons.

 use POSIX; 

It will import all the characters from the POSIX @EXPORT in the space of the calling module names.

 use POSIX(); 

This will not import characters into the calling namespace. However, it loads the module, which means that you can call functions like POSIX::strftime(...) , etc.

 use POSIX(WNOHANG) 

This will only result in entering the WNOHANG character in the namespace of the calling module.

If you are not familiar with the @EXPORT and @EXPORT_OK , you should definitely follow the Exporter documentation. Using Exporter is the standard way in Perl to export characters from one module to your module's namespace (namespace). POSIX also uses it.

It is also probably worth mentioning that modules designed with an object-oriented interface usually do not require importing characters.

+13
source

Source: https://habr.com/ru/post/955295/


All Articles