home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / perl / 7572 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.6 KB  |  79 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!news.cerf.net!netlabs!lwall
  3. From: lwall@netlabs.com (Larry Wall)
  4. Subject: Re: Details regarding the exec command
  5. Message-ID: <1992Dec21.202418.10520@netlabs.com>
  6. Sender: news@netlabs.com
  7. Nntp-Posting-Host: scalpel.netlabs.com
  8. Organization: NetLabs, Inc.
  9. References: <BzH641.L0J@cs.uiuc.edu>
  10. Date: Mon, 21 Dec 1992 20:24:18 GMT
  11. Lines: 66
  12.  
  13. In article <BzH641.L0J@cs.uiuc.edu> schwager@mike.cs.uiuc.edu (Mike Schwager) writes:
  14. : Everyone please open their Bibles to page 143... :-)
  15. : I'm trying to understand the "exec" call better.  I notice on the
  16. : aforementioned page that if I do
  17. : $shell = '/bin/csh';
  18. : exec $shell '-sh';
  19. : die "barf\n";
  20. : Then the shell believes it is a login shell- ie, $0 must be "-".  However,
  21. : if I do this:
  22. : exec '/bin/csh' '-sh';
  23. : it gives me an error, and if I do this:
  24. : exec $shell, '-sh';
  25. : it is not a login shell.  I don't understand The Book here, nor is it clear
  26. : what a "multi-valued list" is.  What exactly is exec'ed in the first
  27. : example?  Why does it work, whereas if I explicitly use the string
  28. : '/bin/csh' it fails?  Please enlighten me.
  29.  
  30. List operators have what has been called the filehandle slot, and that
  31. nowadays I tend to call the indirect object.  The distinguishing feature
  32. syntactically is that there is no comma separating that argument from
  33. the following argument.  This imposes some rather tight constraints
  34. on what can be put into that grammatical slot.  Only three things
  35. are allowed currently: a bare word, a simple scalar variable, or
  36. a block.
  37.  
  38. The print operators use this to specify a filehandle.  Certain other
  39. operators use this slot for other purposes.  For instance, the
  40. sort operator either looks for a subroutine name or an inlined
  41. block of code.  The exec routine looks for the name of the program
  42. to "really" execute.
  43.  
  44. I could conceivable allow a quoted string in the filehandle slot,
  45. but I'm afraid that it would lead rather quickly to unreadable code,
  46. since it's more difficult visually to find the end of a quoted string
  47. than the end of a bare word, a variable name, or a block.  In Perl 5
  48. you'll be able to say
  49.  
  50.     exec { "/bin/csh" } '-sh';
  51.  
  52. That's also supposed to work in 4.035, but it didn't seem to when I tried it.
  53.  
  54. The reason I call that the indirect object slot is by analogy between
  55.  
  56.     print STDOUT $foo;
  57.  
  58. and
  59.  
  60.     give DOG $bone;
  61.  
  62. And in fact, the latter would be equivalent in Perl 5 to
  63.  
  64.     DOG->give($bone);
  65.  
  66. [Note to Raphael:  yes, I agree about optimizing method lookup in the
  67. absence of redefinition--thanks for the suggestion.]
  68.  
  69. Larry
  70.