I'm trying to learn Perl and understand something about use
and modules.
(Assume use strict; use warnings;
)
I understand that use File::Find;
loads all the subroutines of the module.
I understand that use File::Find qw(find);
loads only the find
subroutine of the module (although other subroutines my be used via File::Find::finddepth
).
So what does File::Find ();
do? Specifically, why the empty parens?
tl;dr : It says not to export anything instead of the default.
long version:
File::Find has our @EXPORT = qw(find finddepth);
, so those subs are exported by default. If we just use the module and then try to call find
it errors because I didn't pass it the right arguments to find
but find
does exist.
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 the use
statement overrides the defaults and exports only the subs that you ask for. An empty list means that none will be exported and it will error because find
doesn't exist. Such:
quentin@workstation:~ # perl
use File::Find ();
find();
Undefined subroutine &main::find called at - line 2.
So what does File::Find (); do? Specifically, why the empty parens?
In short, you require-ing this module and calling File::Find::import
to import functions (like find
and finddepth
in your example). So empty brackets mean you dont want import anything, and implicitly forbid to import any default symbols.
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