home *** CD-ROM | disk | FTP | other *** search
/ ftp.cse.unsw.edu.au / 2014.06.ftp.cse.unsw.edu.au.tar / ftp.cse.unsw.edu.au / pub / doc / languages / perl / nutshell / ch3 / dumpvar.pl < prev    next >
Encoding:
Perl Script  |  1992-10-18  |  1.0 KB  |  49 lines

  1. package dumpvar;
  2.  
  3. sub main'dumpvar {
  4.     ($package) = @_;
  5.  
  6.     # This next line gives us an alias for the associative array
  7.     # containing the symbol table for the specified package.
  8.  
  9.     local(*stab) = eval("*_$package");
  10.  
  11.     # Now that we have defined %stab, look at all the symbol
  12.     # table entries it contains.
  13.  
  14.     while (($key,$val) = each(%stab)) {
  15.  
  16.     # Alias the particular symbol table entry.
  17.  
  18.     local(*entry) = $val;
  19.  
  20.     # Now check for different objects of that name.
  21.     # Is there a scalar?
  22.  
  23.     if (defined $entry) {
  24.         print "\$$key = '$entry'\n";
  25.     }
  26.  
  27.     # Is there a normal array?
  28.  
  29.     if (defined @entry) {
  30.         print "\@$key = (\n";
  31.         foreach $num ($[ .. $#entry) {
  32.         print "  $num\t'",$entry[$num],"'\n";
  33.         }
  34.         print ")\n";
  35.     }
  36.  
  37.     # Is there an associative array that isn't the one
  38.     # we're currently iterating through?
  39.  
  40.     if ($key ne "_$package" && defined %entry) {
  41.         print "\%$key = (\n";
  42.         foreach $key (sort keys(%entry)) {
  43.         print "  $key\t'",$entry{$key},"'\n";
  44.         }
  45.         print ")\n";
  46.     }
  47.     }
  48. }
  49.