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

Re: Avoiding variable conflict when importing modules

by btrott (Parson)
on Jun 25, 2001 at 02:40 UTC ( [id://91139]=note: print w/replies, xml ) Need Help??


in reply to Avoiding variable conflict when importing modules

In this situation, whichever function sub was imported last will be called. If you have warnings enabled, you will get a warning when importing a function that has already been defined/imported; you won't get such a warning w/ a variable (at least I don't think you will).

This is why you have to be careful when writing modules that export; you can easily trample someone else's namespace. Which is part of the reason why module authors are encouraged to use @EXPORT_OK instead of @EXPORT; you give the user of your module the choice of which functions/variables he/she imports, plus you make it very explicit to any reader of your code (including you :) which functions and variables you're importing. Ie. you can look at the use line and *know* what you're importing into your namespace.

  • Comment on Re: Avoiding variable conflict when importing modules

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-19 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found