indent based on stack

B

bjlockie

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.

eg.
START.1
START.2
START.3
END.3
END.2
END.1
 
T

Tim McDaniel

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.

eg.
START.1
START.2
START.3
END.3
END.2
END.1

([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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top