in reply to Getting size of call stack

my $depth = 0; $depth++ while caller($depth);
Will give you the depth of the stack for the current frame in the $depth variable.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Getting size of call stack
by Sprad (Hermit) on Nov 07, 2003 at 17:07 UTC
    Yes, this works fine. I tweaked it a bit, setting $depth to -1 and putting the code in a GetCallStackDepth sub. Cool!

    ---
    A fair fight is a sign of poor planning.

      I tweaked it a bit, setting $depth to -1

      Wouldn't your subroutine always return -1? Shouldn't your GetCallStackDepth look more like:

      sub GetCallStackDepth { my $depth = 1; # 0 is this sub, why bother checking it? $depth++ while caller($depth); return $depth - 1; }
        Wouldn't your subroutine always return -1?

        Duh. Yes, of course. Returning $depth - 1 is what I actually did, and on my way from the editor to here, I thought, "Hey, I can save a step by just initializing $depth to -1 to begin with!". And I wrote it down before I actually tried it.

        Busted...

        ---
        A fair fight is a sign of poor planning.