home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7494 < prev    next >
Encoding:
Internet Message Format  |  1992-12-17  |  2.3 KB

  1. Path: sparky!uunet!nntp1.radiomail.net!fernwood!autodesk!dansmith
  2. From: dansmith@Autodesk.COM (Daniel Smith)
  3. Newsgroups: comp.lang.perl
  4. Subject: switching off symtabs via %_foo assignments?
  5. Message-ID: <18160@autodesk.COM>
  6. Date: 17 Dec 92 19:31:33 GMT
  7. Organization: Autodesk Inc., Sausalito CA, USA
  8. Lines: 52
  9.  
  10.  
  11.     Let's say you have some interactive Perl script, and you
  12. want to have more than one instantiation [1] of it, but that you want
  13. to do that within the same process...
  14.  
  15. [1] as in, you want to push a menu and use the same routines and all,
  16. but have a unique set of variables for that "push"
  17.  
  18.     I've thought of going through something I'm writing and
  19. putting "$instance_name'some_var" in place of "$some_var".  I don't like
  20. that idea :-)
  21.  
  22.     I'm wondering if it's "safe" to swap "%_some_package" around.  Let's
  23. say I fire off my script, and I'm in the "main" package.  So far so good...
  24. Now before getting too far into the code, I say something like:
  25.  
  26.     eval "package instance_1";
  27.     %_instance_1 = %_main;
  28.  
  29.     So now I'm in a "instance_1" context, right?  I think it means
  30. that I just picked up the entire symtab from main (bear with me, I'm still
  31. trying to figure this stuff out).  I think I get a benefit of not having
  32. to change any code.
  33.  
  34.     If I now want an "instance_2", I suppose I could do:
  35.     
  36.     eval "package instance_2";
  37.     %_instance_2 = %_main;
  38.  
  39.     or
  40.  
  41.     %_instance_2 = %_instance_1;
  42.  
  43.     to easily inherit what "instance_1" was doing...
  44.  
  45.     The tricky part (as if this isn't bad enough!) seems to be in
  46. going from one instance to another.  I can't just say "package" again,
  47. since it clobbers all of the vars in the package.  At this point I'm
  48. starting to run out of steam (other than the idea of caching away the
  49. symtab of an instance so that I can grab it back later).  I think
  50. Tom C. has something like this going on in Plum for mail folders. I'm
  51. thinking of applying it to pretty much the whole script though.  Any ideas?
  52. I'm also somewhat concerned about how portable this might be.  A little
  53. experimentation on a SPARC is fine, but I want to get a little feedback
  54. about possible hiccups on other platforms.
  55.  
  56.                 Daniel
  57. -- 
  58.      Daniel Smith, Autodesk, Sausalito, California, (415) 332-2344 x 2580
  59.           Disclaimer: written by a highly caffeinated mammal
  60.         dansmith@autodesk.com            dansmith@well.sf.ca.us
  61.  
  62.