print all current variables

S

simon

i'm looking for a snippet of perl code that will print all currently
defined perl variables (not just cgi and/or environment) and their
current value. it is ok (but not necessary) for array variables with
null values are not displayed. using debug mode is not an option.

foreach $key (sort keys(%ENV)) {print "\n$key = $ENV{$key}";}

lists the environment variables, but i want to see all defined
variables.
 
B

Bob Walton

simon said:
i'm looking for a snippet of perl code that will print all currently
defined perl variables (not just cgi and/or environment) and their
current value. it is ok (but not necessary) for array variables with
null values are not displayed. using debug mode is not an option.

foreach $key (sort keys(%ENV)) {print "\n$key = $ENV{$key}";}

lists the environment variables, but i want to see all defined
variables.

Well, you could print the main symbol table. But that won't show
variables in other packages, or lexical variables.

$q='hi there';
print "$_=$$_\n" for sort keys %main::

That needs fancying up if it is to print the values of arrays and
hashes -- the above prints only scalars. For the proper way to
do it, check "Advanced Perl Programming" pp 95-97.
 

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,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top