Getting a list of all current variables in a Perl program

J

James E Keenan

From a 1997 posting by Randal L Schwartz on this list, I got the
following code as a way to get a list of all (or most ??) identifiers in
a program at a given point.

print "\n\n" .
Dumper ({
map {
(defined $$_ ? ("\$$_" => $$_) : ()),
(defined @$_ ? ("\@$_" => \@$_) : ()),
(defined %$_ ? ("\%$_" => \%$_) : ()),
} sort keys %{__PACKAGE__."::"}
});

1. Are there any better ways to approach this problem?
2. In addition to package variables, how can I get a list of the
lexical variables declared at a given point in a program? (I think this
means the content of the scratchpad(s)?)

TIA

Jim Keenan
 
J

John W. Krahn

James said:
From a 1997 posting by Randal L Schwartz on this list, I got the
following code as a way to get a list of all (or most ??) identifiers in
a program at a given point.

print "\n\n" .
Dumper ({
map {
(defined $$_ ? ("\$$_" => $$_) : ()),
(defined @$_ ? ("\@$_" => \@$_) : ()),
(defined %$_ ? ("\%$_" => \%$_) : ()),
} sort keys %{__PACKAGE__."::"}
});

1. Are there any better ways to approach this problem?
2. In addition to package variables, how can I get a list of the
lexical variables declared at a given point in a program? (I think this
means the content of the scratchpad(s)?)

perldoc B::Xref
perldoc B::Showlex


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top