本文介绍了发现Perl应用程序当前定义的所有变量的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在寻找最好,最简单的方法来做类似的事情:

I am looking for best, easiest way to do something like:

$var1="value";
bunch of code.....
**print allVariablesAndTheirValuesCurrentlyDefined;**

推荐答案

包装变量?词汇变量?

可以通过符号表查询包装变量.尝试 Devel :: Symdump :

Package variables can be looked up via the symbol table. Try Devel::Symdump:

#!/path/to/perl

use Devel::Symdump;

package example;

$var = "value";
@var = ("value1", "value2");
%var = ("key1" => "value1", "key2" => "value2");

my $obj = Devel::Symdump->new('example');

print $obj->as_string();

词法变量有点麻烦,您不会在符号表中找到它们.可以通过属于其定义代码块的便签本"来查找它们.请尝试 PadWalker :

Lexical variables are a little tricker, you won't find them in the symbol table. They can be looked up via the 'scratchpad' that belongs to the block of code they're defined in. Try PadWalker:

#!/path/to/perl

use strict;
use warnings;

use Data::Dumper;
use PadWalker qw(peek_my);

my $var = "value";
my @var = ("value1", "value2");
my %var = ("key1" =>  "value1", "key2" => "value2");

my $hash_ref = peek_my(0);

print Dumper($hash_ref);

这篇关于发现Perl应用程序当前定义的所有变量的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:00