'caller' is stacktrace in perl. You could know who calls the subroutine by caller.
Read these code below:
- sub m1{
- }
- sub m2{
- &m1;
- }
- sub m3{
- &m2;
- }
Take a look at the 3 subroutines. You can find m3 calls m2, and m2 calls m1.
If you call subroutine 'm1' in your main, when reached m1 code block, the content of caller is:
caller[0] = m1
caller[1] = main
If you call 'm2' in your main, whe reached m2 code block, the content of caller is
caller[0] = m1
caller[2] = m2
caller[3] = main
Similar, if you called m3, the caller should be:
caller[0] = m1
caller[1] = m2
caller[3] = m3
caller[4] = m4
You can find a full example here:
阅读(968) | 评论(0) | 转发(0) |