How to tie every variable in perl script?

青春壹個敷衍的年華 提交于 2019-12-01 18:04:15

问题


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

It is easily reachable using tie or Variable::Magic

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/42434132/how-to-tie-every-variable-in-perl-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!