in reply to sub running on use statement

Your story isn't consistent. For a start use statements are executed during the compilation phase before any "normal" code is run so the output you suggest you see is not what I'd expect to see. Indeed, when I run the following code:

####### ScrewyModule.pm package ScrewyModule; use strict; use warnings; ScrewySubRoutine(); sub ScrewySubRoutine { print "running the sub\n"; } return 1; ####### noname.pl #!C:\Perl\bin use diagnostics; use strict; print "before use\n"; use ScrewyModule; print "after use\n";

I get:

running the sub before use after use

as expected.

Note though that I have an explicit call to ScrewySubRoutine in the module. If I omit that line then ScrewySubRoutine does not get called. I suspect that you have a call to ScrewySubRoutine in your module code outside any sub. Maybe you should run your code through PerlTidy to make sure the indentation is correct then go looking for unexpected code?

Perl is the programming world's equivalent of English

Replies are listed 'Best First'.
Re^2: sub running on use statement
by Anonymous Monk on Dec 02, 2014 at 17:05 UTC
    You're correct - the output is as you state. Apologies for the error. I was a bit fuzzy at the end of a long day.

    You're also correct about the calls to other subs in other modules. I've had a practice of taking segments of code that I use in several modules or scripts and putting them into subs in another module.

    Thanks for your response. You did clear up something that I was uninformed about with regard to sub-routines and modules.