Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
This can be done, but not quite as simply as you had perhaps hoped
use strict; use warnings; ## disable perl's warning mechanism no warnings 'recursion'; use B 'svref_2object'; use Symbol 'qualify_to_ref'; sub change_depth_warn { my($subname, $limit) = @_; my $subref = \&$subname; my $gv = svref_2object($subref)->GV; my $lineno = 0; no warnings 'redefine'; *{ qualify_to_ref $subname } = sub { if( $gv->CV->DEPTH % $limit == 0 ) { $lineno = do { my $i = 0; 1 while caller $i++; (caller($i - 2))[2] } unless $lineno; warn sprintf "Deep recursion on subroutine '%s' at %s line %d.\n", join('::', $gv->STASH->NAME, $gv->NAME), $0, $lineno; } &$subref(@_); }; } my $cnt = 0; sub foo { &foo while $cnt++ < $_[0] } my $maxdepth = 1000; my $recdepth = 3000; change_depth_warn('foo', $maxdepth); printf "calling foo(), expecting %d warnings ...\n", $recdepth / $maxdepth; foo($recdepth); __output__ calling foo(), expecting 3 warnings ... Deep recursion on subroutine 'main::foo' at perlmonks/pmsopw_324564.pl + line 43. Deep recursion on subroutine 'main::foo' at perlmonks/pmsopw_324564.pl + line 43. Deep recursion on subroutine 'main::foo' at perlmonks/pmsopw_324564.pl + line 43.
So that disables the recursion warning, and then wraps the foo() in a closure that emits a recursion warning for every $limitth recursion.
HTH

_________
broquaint


In reply to Re: Deep Recursion Limit by broquaint
in thread Deep Recursion Limit by greatdane

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (8)
    As of 2015-07-30 00:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (269 votes), past polls