indent based on stack

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am doing this for each subroutine.
print 'START.' . (caller(0))[3] . "\n"; and
print 'END.' . (caller(0))[3] . "\n";

What I would like to do is add a space after the START. for each level
down the stack it is.


Re: indent based on stack

Quoted text here. Click to load it

([3] is the name of the subroutine, so 1, 2, and 3 above represent
subroutine names.)

A little experimentation shows that caller(N) returns a zero-length
list when N is larger than the number of layers of call.  So you can
loop, calling "my @a = caller($i);" until scalar @a == 0.
The "x" operator, for A x B, returns a string being B copies of the
string value of A, so ' ' x $n returns a string of $n spaces.

Tim McDaniel,

Site Timeline