Using a Perl Module with Empty Parentheses

I am trying to learn Perl and understand something about use and modules.

(Assume use strict; use warnings; )

I understand that use File::Find; loads all module routines.

I understand that use File::Find qw(find); it loads only the module find routine (although other my routines will be used through File::Find::finddepth ).

So what does File::Find (); ? In particular, why are empty partners?

+4
source share
2 answers

tl; dr: He says don't export anything, not the default.

long version:

The file :: Find has our @EXPORT = qw(find finddepth); therefore these subnets are exported by default. If we just use the module, and then try to call find its errors, because I did not pass the correct find arguments to it, but find exists.

 quentin@workstation :~ # perl use File::Find; find(); no &wanted subroutine given at /Users/david/perl5/perlbrew/perls/perl-5.16.1/lib/5.16.1/File/Find.pm line 1064. 

Passing a list in a use expression overrides the default values ​​and exports only the children you request. An empty list means that no one will be exported, and it will be an error because find does not exist. Such:

 quentin@workstation :~ # perl use File::Find (); find(); Undefined subroutine &main::find called at - line 2. 
+9
source

So what does File :: Find (); make? In particular, why are empty partners?

In short, you need - this module and a call to File::Find::import to import functions (for example, find and finddepth in your example). Thus, empty brackets mean that you do not want to import anything and implicitly prohibit the import of any default characters.

+1
source

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


All Articles