Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > indent based on stack

Reply
Thread Tools

indent based on stack

 
 
bjlockie
Guest
Posts: n/a
 
      03-23-2012
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
 
Reply With Quote
 
 
 
 
Tim McDaniel
Guest
Posts: n/a
 
      03-23-2012
In article <(E-Mail Removed)>,
bjlockie <(E-Mail Removed)> wrote:
>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.

--
Tim McDaniel, http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does std::stack::pop() not throw an exception if the stack is empty? Debajit Adhikary C++ 36 02-10-2011 08:54 PM
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
stack frame size on linux/solaris of a running application stack Surinder Singh C Programming 1 12-20-2007 01:16 PM
gnu indent: how to avoid extra indent? dt C Programming 4 12-31-2006 11:31 AM
is RITE stack based or register based VM? rolo Ruby 5 04-05-2004 08:02 PM



Advertisments