Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Namespaces & colliding names

by kcott (Archbishop)
on Nov 08, 2016 at 09:26 UTC ( [id://1175528]=note: print w/replies, xml ) Need Help??


in reply to Namespaces & colliding names

G'day jahero,

Welcome to the Monastery.

++Athanasius showed in his response how to stop all imports with:

use File::Basename ();

However, there may be cases where you only want to stop some, but not all, imports. Still using File::Basename as an example, let's say you wanted its dirname() function. You can specify importation of that function like this:

use File::Basename qw{dirname};

Module documentation will often identify which functions are exported by default and which are optionally exported; however, presence of this information is by no means guaranteed. You can check for yourself by looking at the source code: @EXPORT lists the default exports and @EXPORT_OK lists the optional ones. For example, the File::Basename source code shows four default exports:

@EXPORT = qw(fileparse fileparse_set_fstype basename dirname);

See Exporter for a lot more information on this including advanced features. For instance, to exclude basename() only, you could write:

use File::Basename qw{!basename};

— Ken

Replies are listed 'Best First'.
Re^2: Namespaces & colliding names
by jahero (Pilgrim) on Nov 08, 2016 at 09:34 UTC
    Thank you, I was not aware that one can also exclude certain parts of the module from import.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1175528]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-29 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found