in reply to Re: Getting size of call stack
in thread Getting size of call stack

I like that you have both the stack to inspect (eg. dump it to stderr) and the stack depth (scalar(@stack))

For my liking though, this is more intuitive:

my @stack; my $depth = 0; while (my @frame = caller $depth++) { push @stack, \@frame[0,1,2]; }

Replies are listed 'Best First'.
Re^3: Getting size of call stack
by diotalevi (Canon) on Jan 30, 2005 at 01:09 UTC
    The entire purpose of the for(;;) loop is to handle preinitializations and temporary variables like your my $depth = 0 and to separate your test scalar( @frame ) from your NEXT() in $depth++.
      I guess I've never like shoe-horning code inside the c-like for operator.

      There's also no need to keep track of a seperate $depth since it's the same as scalar(@stack).

      My version seems easier to read and more descriptive of what's actually happening. That's just a personal preference though...