|laziness, impatience, and hubris|
Can I from within a module access variables from the calling program?by HJO (Acolyte)
|on Oct 25, 2012 at 11:03 UTC||Need Help??|
HJO has asked for the
wisdom of the Perl Monks concerning the following question:
I saw earlier in the Chatterbox this question and an answer, and it catched my attention... The answer was "Yes, but it is commonly considered bad practice. You can easily access global variables of the main program: $main::foo gives access to $foo in the main program"
I tried this and obviously it didn't work, so I searched a little and came on this page : Variable Scoping in Perl: the basics, which I saddly didn't understand as good as I would like to :( basically, I understood that there were 3 was to declare a variable, my our and local, after that I kinda lost myself in the subtilities of each method...
So here is my problem : I'm working on a script which uses Log::Log4perl to log pretty much everything I do. I'm calling a homemade module which also needs logging, so I copied/pasted the configuration of Log::Log4perl in it (I don't use an external configuration file for some reasons I'm not going to explain because it would be too long and off topic...) but the name of my .log file is a variable based on the date and time of my system, and I'm afraid that if there's a change in the time (like script launched at 12:12:12 and module called at 12:12:13), I'll end up with two .log files...
So after having though of some horrible methods on my own, this solution to call this variable from the main sript into the module seems perfect... Could someone please help me a little by giving me a very simple explanation on how I need to organize my script/module to make this work ?
I don't know what to give you as additional informations to help me, but here is my configuration of Log::Log4perl, maybe you'll see my problem more clearly ^^" :
And here if what I'd hope to use in the module :
Thank you, Regards