in reply to Getting the size of the call stack (efficiently)

The call stack depth as a whole is not usually what interests me but more often the depth of recursion, which more often corresponds with the depth of something in the input.

In that case it's a simple matter of incrementing a depth counter on entry and decrementing it just before the return, e.g.

sub gettag { my $self = shift; ($self -> { THIS }{ DEPTH } ||= 0)++; my $tagref = { SUBTAG => [] }; # ... while ( !/<\// ) { push @{$tagref -> { SUBTAG }}, $self -> gettag(); # recursive call } # ... $self -> { THIS }{ DEPTH }--; return $tagref; }

-M

Free your mind