[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] recursion stack limits?



At 20.46 -0500 01.01.1999, Michael Brian Bentley wrote:
>I'm seeing a few instances of:
>
># Deep recursion on subroutine "main::fetch".
>
>What is this actually in terms of the depth of the recursion stack, and how
>do I make it deeper?

It is an arbitrary limit of 100.  You could make it deeper by recompiling
MacPerl.  :-)

You can also silence the warning, though:

#!perl -wl
$count = 0;
print fetch();

sub fetch {
  ++$count;
  return $count if $count == 100;  # no warn with 99
  fetch();
}

BEGIN {
  $SIG{__WARN__} = sub {warn @_ unless $_[0] =~ /recursion/};
}

__END__

If you want to be really tricky, you can keep it to only a particular sub.
If this is in a module, you might want to use local() on it, like so:

#!perl -wl
# keep at top so you can use local() on it
local $SIG{__WARN__} = sub {
  warn @_ unless
    $_[0] =~ /recursion/ &&
    (caller(1))[3] eq 'main::fetch'
};


$count = 0;
print fetch();
$count = 0;
print fetch2();

sub fetch {
  ++$count;
  return $count if $count == 100;  # no warn with 99
  fetch();
}

sub fetch2 {
  ++$count;
  return $count if $count == 100;  # no warn with 99
  fetch2();
}

__END__

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch