Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Getting a list of all current variables in a Perl program (http://www.velocityreviews.com/forums/t895161-getting-a-list-of-all-current-variables-in-a-perl-program.html)

James E Keenan 11-15-2005 03:23 AM

Getting a list of all current variables in a Perl program
 
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

John W. Krahn 11-15-2005 06:24 AM

Re: Getting a list of all current variables in a Perl program
 
James E Keenan wrote:
> 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
--
use Perl;
program
fulfillment

James E Keenan 11-15-2005 12:16 PM

Re: Getting a list of all current variables in a Perl program
 
John W. Krahn wrote:

> James E Keenan wrote:
>
>>
>>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
>

Those look helpful and I will check them out today. Thanks, John!

jimk


All times are GMT. The time now is 11:29 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.