indent based on stack

Discussion in 'Perl Misc' started by bjlockie, Mar 23, 2012.

  1. bjlockie

    bjlockie Guest

    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
    bjlockie, Mar 23, 2012
    #1
    1. Advertising

  2. bjlockie

    Tim McDaniel Guest

    In article <>,
    bjlockie <> 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,
    Tim McDaniel, Mar 23, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dt
    Replies:
    4
    Views:
    479
    CBFalconer
    Dec 31, 2006
  2. Surinder Singh
    Replies:
    1
    Views:
    1,188
    Richard Bos
    Dec 20, 2007
  3. Casey Hawthorne
    Replies:
    3
    Views:
    1,079
    Flash Gordon
    Nov 1, 2009
  4. Debajit Adhikary
    Replies:
    36
    Views:
    2,282
    Andre Kaufmann
    Feb 10, 2011
  5. rolo
    Replies:
    5
    Views:
    526
    Jean-Hugues ROBERT
    Apr 5, 2004
Loading...

Share This Page