in reply to Avoiding variable conflict when importing modules

The function that will be called is the one that was imported last. Importing is basically an assignment; a reference &ModuleA::function is assigned to the *main::{function} glob, and then a reference to &ModuleB::function is assigned to the same glob. The second assignment replacements the first one.

This is why using @EXPORT_OK to specify what your module should export is safer and friendlier than using @EXPORT. With @EXPORT_OK, the person using the module has to specify the functions and variables to be imported, so he or she is more likely to notice any conflicts with other modules.

  • Comment on Re: Avoiding variable conflict when importing modules