如何在perl脚本中绑定每个变量? [英] How to tie every variable in perl script?

查看:232
本文介绍了如何在perl脚本中绑定每个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在perl脚本中创建/访问/销毁变量时看到每个地方

I want to see every place when variable in perl script is created/accessed/destroyed

使用tie Variable::Magic

但是如何在创建变量后自动应用此魔术呢?

But how to apply this magic automatically when variable is created?

推荐答案

您可以看一下B :: Xref,它会生成应用程序中所有变量的交叉引用列表.基本上,您需要遍历字节码以查找所有变量声明/初始化.您还可以更改字节码,即添加代码以绑定变量.但是,我无法为您提供示例,因为很少这样做.

You can take a look at B::Xref which generates a cross reference listing of all variables in your application. Basically, you need to walk the byte code to find all variable declarations/initializations. You can also alter the byte code, i.e. add code to tie the variables. However, I cannot point you to an example, because this is rarely done.

作为替代方案,您可以使用代码过滤器添加tie()指令.但是,不能保证代码过滤器可以正确识别变量声明/初始化.

As an alternative, you could use a code filter to add the tie() instructions. However, code filters are not guaranteed to correctly identify variable declarations/initializations.

这篇关于如何在perl脚本中绑定每个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆