in reply to Seeking the right way to override global variables
Hello contra-sh, and welcome to the Monastery!
I’ll just address one part of your question:
Seems like the override only works when I call the function. That's weird because I modified the value before including the logging module.
No you didn’t! use logging; is the same as BEGIN { require Module; }, which means that the code in “logging.pm” is loaded and run before the rest of the script begins running (because anything in a BEGIN block is run at compile time). Change that line in “run-unit-tests.pl” to require logging; and the output is:
23:48 >perl 1030_SoPW.pl Import... VAR1 : [override1] VAR2 : [override2] Running function... VAR1 : [override1] VAR2 : [override2] 23:48 >
- Should I see any difference if I use require instead of use?
Yes! (as just explained).
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Seeking the right way to override global variables
by contra-sh (Acolyte) on Sep 26, 2014 at 14:41 UTC |