Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Avoiding variable conflict when importing modules

by btrott (Parson)
on Jun 25, 2001 at 02:40 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-12-04 19:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found