DrWhy has asked for the wisdom of the Perl Monks concerning the following question:
(That's my own implementation of the algorithm.)for ($depth = 0; caller $depth; $depth++) {1}
This is a pretty inefficent way to get the stack depth. For implementations where this is only needed once, e.g. as part of generating a die message, that's not much of an issue. I have a tracing module that produces lots of debugging output, and I'd like to add an indication of the stack depth to each line of debug output -- that would lead to alot of repetition of this loop.
Does anyone know of a more efficient method for finding just the stack depth without using multiple calls to caller() each time you need that number?
--DrWhy
"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting the size of the call stack (efficiently)
by kyle (Abbot) on Feb 27, 2007 at 18:32 UTC | |
by Anno (Deacon) on Feb 27, 2007 at 18:39 UTC | |
by kyle (Abbot) on Feb 27, 2007 at 18:44 UTC | |
by Anno (Deacon) on Feb 27, 2007 at 20:37 UTC | |
|
Re: Getting the size of the call stack (efficiently)
by grinder (Bishop) on Feb 27, 2007 at 18:42 UTC | |
by DrWhy (Chaplain) on Feb 28, 2007 at 01:27 UTC | |
|
Re: Getting the size of the call stack (efficiently)
by xdg (Monsignor) on Feb 28, 2007 at 11:48 UTC | |
by DrWhy (Chaplain) on Mar 01, 2007 at 00:18 UTC | |
|
Re: Getting the size of the call stack (efficiently)
by Moron (Curate) on Mar 01, 2007 at 14:22 UTC |