【发布时间】:2010-10-19 08:26:05
【问题描述】:
我知道我可以使用Padwalker 的peek_our 和peek_my 列出给定范围内的所有包变量和词法变量,但是如何获取所有全局变量的名称和值,例如@ 987654325@和$/?
#!/usr/bin/perl
use strict;
use warnings;
use PadWalker qw/peek_our peek_my/;
use Data::Dumper;
our $foo = 1;
our $bar = 2;
{
my $foo = 3;
print Dumper in_scope_variables();
}
print Dumper in_scope_variables();
sub in_scope_variables {
my %in_scope = %{peek_our(1)};
my $lexical = peek_my(1);
#lexicals hide package variables
while (my ($var, $ref) = each %$lexical) {
$in_scope{$var} = $ref;
}
##############################################
#FIXME: need to add globals to %in_scope here#
##############################################
return \%in_scope;
}
【问题讨论】:
标签: perl