home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5909 < prev    next >
Encoding:
Text File  |  1992-09-13  |  1.7 KB  |  46 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!convex!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: how to find all current package names?
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Sep14.000832.10143@news.eng.convex.com>
  8. Date: Mon, 14 Sep 1992 00:08:32 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <17597@autodesk.COM>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. X-Disclaimer: This message was written by a user at CONVEX Computer
  14.               Corp. The opinions expressed are those of the user and
  15.               not necessarily those of CONVEX.
  16. Lines: 28
  17.  
  18. From the keyboard of dansmith@Autodesk.COM (Daniel Smith):
  19. :
  20. :    You have a script.  You've included some libraries,
  21. :so you have more than just %_main.  Now, how would you find out
  22. :the names of all of the current packages?
  23.  
  24. This will get you 99.9% of the way. it would miss some pathological cases
  25. that you probably can't generate without trying really hard, such as
  26. package names that aren't valid identifiers.   But if you're doing that,
  27. you'll probably understand how to modify this code to find them, too.
  28.  
  29.     foreach $package (keys %_main) {
  30.     next unless $package =~ /^_/;
  31.     $val = $_main{$package};
  32.     next unless $val =~ /^StB/;
  33.     *stab = eval("*$package");
  34.     foreach $ident (keys %stab) {
  35.         print substr($package, 1)."\n" if $stab{$ident} =~ /^StB/;
  36.         last;
  37.     }
  38.     }
  39.  
  40. --tom
  41. -- 
  42.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  43.  
  44.     It is, of course, written in Perl.  Translation to C is left as an
  45.     exercise for the reader.  :-)  --Larry Wall in <7448@jpl-devvax.JPL.NASA.GOV>
  46.