> 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 ☆☆☆☆ :)


In reply to Re^4: sub running on use statement (Isolating with Carp::cluck() ) by LanX
in thread 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.