Every package has a symbol table to store the variables. Here it is demonstrated how the contents of the main symbol table is displayed:
#!/usr/bin/perl -w use strict; use vars qw( *sym); foreach my $symname ( sort keys %main::) { local *sym = $main::{ $symname}; print " \$$symname is defined \n" if defined $sym; print " \@$symname is defined \n" if defined @sym; print " \%$symname is defined \n" if defined %sym; }
In other words, this script show all global variables.
Every package symbol table is referenced in %main::
.
Note that %main
contains a reference to itself.
This has to be taken into account before recursively running
over all entries of %main::
and the other symbol
tables to find all variables.