Syntactic Confectionery Delight | |
PerlMonks |
Conditional loading of module with global exportsby learnedbyerror (Monk) |
on Feb 22, 2016 at 19:26 UTC ( [id://1155832]=perlquestion: print w/replies, xml ) | Need Help?? |
learnedbyerror has asked for the wisdom of the Perl Monks concerning the following question: Spoiler - the author of this message is an idiot - signed said idiot In the poor idiots defense, he blindly put his faith in "use strict" and trusted that any message issued by it was "gospel". This includes believing it when says that a Global Symbol name does not exist that it indeed does not exist. I need to do more research on this, but it appears "use strict" does not know when a symbol has been exported via an import following a require.
But this good faith gaff alone doesn't raise one to the ignoble title of idiot; however, creating a test case with two scripts containing the snippet "Key => $0" in two different files where this "Key" determines how the module in question persists data and where the issue is about data persistence surely does! Yes, I am an idiot!! So my thanks to the original responder - Anonymous Monk on Feb 22, 2016 at 20:58 UTC. Your guidance would have worked properly "if" I had not subtly, but totally, screwed up my test case!! Thank you kind Monk. Oh Knowledgeable Ones, My perl knowledge is proven yet again insufficient. I kindly ask your indulgence in answering me the following: I am creating a script to download pages from various web sites and save the pages to a local file. I want to have the option to either persist the list in a form that could be shared by multiple instantiations of this script using IPC::Lite or to have it run independently using a non-persisted list in RAM. Furthermore, I want to be able to execute the script giving it a list to use in RAM and have it not interact at all with the persisted lists I have used IPC::Lite for many years and am aware of its pros and cons. In the past, I have always loaded via use
This approach loads the modules and exports @urls at compile time. However, in this script I prefer to load it at run time depending upon the command line options that I pass. I have tried to use require; however, I receive a compilation error that the exported variable, @urls in this case, is not declared. Please see the following example
As I researched my problem, I found an alternative approach using the use method of UNIVERSAL::require; however, it failed similarly
The only option that I see at this time is to create separate packages with accessors to totally abstract the list access. I often use this mechanism on larger scripts and realize its value from an isolation and maintenance perspective; however, this is perl dammit and TIMTOWTDI :) More importantly than just wanting to do it my way, I suspect that this points to a deficit in my perl knowledge and I want to make sure that I understand how to conditionally load modules that export globals. Please accept my gracious thanks in advance for helping me address this deficit in my knowledge lbe
Back to
Seekers of Perl Wisdom
|
|