home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / perl / 6856 < prev    next >
Encoding:
Internet Message Format  |  1992-11-04  |  1.3 KB

  1. Path: sparky!uunet!ogicse!reed!mjeffery
  2. From: mjeffery@reed.edu (Mark Jefferys)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Executing required files
  5. Message-ID: <1992Nov5.062131.17033@reed.edu>
  6. Date: 5 Nov 92 06:21:31 GMT
  7. Article-I.D.: reed.1992Nov5.062131.17033
  8. References: <JGD.92Oct21135439@kodiak.acl.lanl.gov> <1992Nov05.052448.29379@spillman.uucp>
  9. Distribution: comp.lang.perl
  10. Organization: Reed College, Portland, OR
  11. Lines: 34
  12.  
  13. In article <1992Nov05.052448.29379@spillman.uucp> tye@spillman.uucp (E. Tye McQueen) writes:
  14. % jgd@acl.lanl.gov (Jerry G. DeLapp) writes:
  15. % )[...] Is there a reliable way of determining whether a
  16. % )program *is being* required or *is being* directly executed?
  17.  
  18. % Perhaps an extension:
  19. %         $^R  The name of the file currently being included by
  20. %              "do" or "require".
  21. % would be nice.
  22.  
  23. A bit redundant, since __FILE__ does most of this already.  I'd like:
  24.  
  25.     __REQUIRED__  Expands to true if file is currently being required.
  26.     __INCLUDED__  Expands to true if file is currently being included
  27.                    by "do" or "require".
  28.  
  29.  
  30. In the meantime, something like:
  31.  
  32.     if (__FILE__ eq $0) {
  33.         # I'm being run directly.
  34.     } else {
  35.         # I'm being run by require, eval, or do,
  36.         # or some idiot set $0.
  37.     }
  38.  
  39. Should work pretty well.
  40.  
  41.  
  42. Mark
  43. -- 
  44. Mark Jefferys        Internet: mjeffery@reed.edu
  45.