Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1003530
  • 博文数量: 150
  • 博客积分: 3017
  • 博客等级: 少校
  • 技术积分: 3829
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-19 14:40
个人简介

Now in Baidu WISE team

文章分类

全部博文(150)

文章存档

2014年(8)

2013年(31)

2012年(111)

分类: Python/Ruby

2012-02-12 18:06:53

'caller' is stacktrace in perl. You could know who calls the subroutine by caller.
 
Read these code below:
  1. sub m1{
  2. }
  3. sub m2{
  4.    &m1;
  5. }
  6. sub m3{
  7.    &m2;
  8. }
Take a look at the 3 subroutines. You can find m3 calls m2, and m2 calls m1.
 
  1. ...
  2. &m1;
  3. ...
If you call subroutine 'm1' in your main, when reached m1 code block, the content of caller is: 
caller[0] = m1
caller[1] = main
 
 
  1. ...
  2. &m2;
  3. ...
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
 
 
  1. ...
  2. &m3;
  3. ...
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) |
给主人留下些什么吧!~~