in reply to Re^2: sub running on use statement
in thread sub running on use statement

Every module is evaluated at use time, but normally a module contains only sub definitions, so nothing is run then (except import() )

BUT if you do unusual stuff like grandfather demonstrated in his first example ScrewyModule.pm , i.e. code is outside of any sub at top level then something like you described can happen.

But that's speculation cause you are not showing us any code.

So please either

Anything else won't lead to results.

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

Replies are listed 'Best First'.
Re^4: sub running on use statement (Isolating with Carp::cluck() )
by LanX (Saint) on Dec 03, 2014 at 00:32 UTC
    > use Carp (see cluck() and confess() ) to force a stack trace at the beginning of the "weird" sub

    put Carp's cluck in the first line of the "strange" sub in the "weird" module

    lanx@lanx-1005HA:/tmp$ cat Weird.pm package Weird; use Carp qw/cluck/; sub tst { cluck "cluck tst entered"; print "\nnormal output in tst()...\n"; # ... } sub tst2 { tst(); } warn "\n--- using Weird.pm\n"; tst2(); # line 17 - executed at "use Weird" time sub import { warn "\n--- importing from Weird.pm\n"; tst2(); # line 22 - executed at Weird::import() time } 1;

    using Weird.pm

    lanx@lanx-1005HA:/tmp$ cat t_carp.pl warn "pre use\n"; use Weird; # ab'use warn "post use\n";

    Output with stacktrace showing all modules/lines leading to problem

    lanx@lanx-1005HA:/tmp$ perl -I. t_carp.pl --- using Weird.pm cluck tst entered at Weird.pm line 6 Weird::tst() called at Weird.pm line 13 Weird::tst2() called at Weird.pm line 17 <--- AHA !!! require Weird.pm called at t_carp.pl line 4 main::BEGIN() called at Weird.pm line 0 eval {...} called at Weird.pm line 0 normal output in tst()... --- importing from Weird.pm cluck tst entered at Weird.pm line 6 Weird::tst() called at Weird.pm line 13 Weird::tst2() called at Weird.pm line 22 <--- AHA !!! Weird::import('Weird') called at t_carp.pl line 4 main::BEGIN() called at t_carp.pl line 4 eval {...} called at t_carp.pl line 4 normal output in tst()... pre use post use

    HTH!

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)