Why Perl doesn't use the "import" routine

I am curious. Most Perl implicitly called routines should be named in all caps. TIESCALAR, DESTROY, etc. Actually perldoc perltoot says

If constructors can have arbitrary names, then why not destructors? Because, although the constructor is explicitly called, the destructor is not. Destruction occurs automatically through the Perl trash (GC), which is a fast, but somewhat lazy GC-oriented system. Know Pearl insists that the destructor is called DESTROY. in Perl, the idea of ​​the right time to call a destructor is not currently defined, so destructors should not rely on when they are called.

Why is DESTROY in all caps? The perl on case uses purely capitalized function names as a symbol for that function to be automatically called by Perl in some way. Others that are called implicitly include BEGIN, END, AUTOLOAD, as well as all methods used by related objects described in perltie.

Why, then, does the import routine remain the bottom line? Does anyone have a good idea about this?

+6
perl implicit naming-conventions
source share
3 answers

To broaden the response to the DVK a bit, there are situations when you really want to explicitly call import , for example, when loading an optional module or automatically populating namespaces:

 eval "require $modulename; $modulename->import( LIST ); "; 

I can't think of any situation when you someday want to call DESTROY, TIESCALAR, etc. obviously.

+3
source share

I would say that " import " is not called implicitly. This is an explicit call issued during the implementation of use . To quote perldoc use :

This is exactly equivalent to:

BEGIN { require Module; Module->import( LIST ); }

+6
source share

This is just a design oversight. Too late to change.

+1
source share

All Articles