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.


In reply to sub running on use statement by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.