perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric L. Brine" <...@iname.com>
Subject Re: ScratchPads
Date Thu, 16 Mar 2000 05:07:09 GMT

> Is there any simple (as easy as getting to the symbol table) way of
> dumping the contents of the current scratchpad? I'd like to dump a
> list of lexical variables in use and their values but am having a hard 
> time finding out how it's done (if at all).

I don't know if this is what you want, but this .pm I wrote a while back
might be of use.
ELB


# The following line is commented out to limit the number
# of changes this module makes in the symbol table.
#use strict;


# ===


package dump_symtab;


sub dump_symtab {
  my $pkg;
  my $pkg_name;
  my $glob;
  my $ref;
  my $found;
  my @packages;

  push(@packages, [\%main::, 'main']);

  while (scalar(@packages)) {
    ($pkg, $pkg_name) = @{pop(@packages)};

    print('package ', $pkg_name, "\n");
    print('=' x (8+length($pkg_name)), "\n");

    foreach (sort(keys(%$pkg))) {
      $found = 0;

      $glob = $pkg->{$_};

      if (($ref = *{$glob}{SCALAR}) && defined($$ref)) {
        print('$', $_, "\n");
        $found = 1;
      }

      if ($ref = *{$glob}{ARRAY}) {
        print('@', $_, "\n");
        $found = 1;
      }

      if ($ref = *{$glob}{HASH}) {
        print('%', $_, "\n");
        $found = 1;
      }

      if ($ref = *{$glob}{CODE}) {
        print('&', $_, "\n");
        $found = 1;
      }

      if (/^(.*)::$/ && $1 ne 'main') {
        push(@packages, [$glob, $1]);
        $found = 1;
      } 

      if (!$found) {
        print('*', $_, "\n");
      }
    }

    print("\n");
  }
}


# ===


1;


__END__
e.g.:
perl -Mdump_symtab -e"dump_symtab::dump_symtab();"


--
Eric L. Brine  |  Chicken: The egg's way of making more eggs.
ELB@iname.com  |  Do you always hit the nail on the thumb?
ICQ# 4629314   |  An optimist thinks thorn bushes have roses.

Mime
View raw message