Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Subroutines in a module have started running themselves on the "use" statement. I've not run across this behavior before and am stumped. Has anyone else seen this happen ?
It's such an odd problem that I wouldn't believe it was happening if I hadn't spent most of the day going over the code. I've even tried the absurd - copied the module text into NotePad, saved it, closed it, deleted the module file, then recreated by opening the NotePad file and copying the text into the newly created empty module file.
I did that in case there was some file error that inserted some unseen control character into the original module file. Bizarre, I know, but I tried it.
I can't duplicate this on another module, or on any running sample code to post. I've tried, and it won't happen.
I tracked it down with a print statement in the module. The print statement runs on the "use ScrewyModule" statement (not the actual module name, I've called that module many unprintable things today). Not just when a subroutine in the module is called - the print statement in the subroutine in that module runs on the "use ScrewyModule" statement.
I tested this because I couldn't really believe it was happening. I put in print statements in the module subroutines, and before and after the "use ScrewyModule;" statement to confirm this. Like so :
I inserted a print statement like the following into any subroutine in the module - didn't matter which one, I got the same result :
sub ScrewySubRoutine { print "\n\nrunning the sub\n\n"; }
Then in the main script I added 'before' and 'after' print statements around the suspect "use" statement :
#!C:\Perl\bin use diagnostics; use strict; print "\n\nbefore use\n\n"; use ScrewyModule; print "\n\nafter use\n\n";
Running that main script with these print statements in the module and main script, this would be the output :
before use
running the sub
after use
If I comment out the "use ScrewyModule;" statement, this would be the output :
before use
after use
I'm really just wondering if anyone has seen this before, and if so, remembers what caused it.
|
|---|