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

  1. Path: sparky!uunet!europa.asd.contel.com!emory!sol.ctr.columbia.edu!spool.mu.edu!agate!doc.ic.ac.uk!uknet!reading!nrp
  2. From: nrp@csug3.cs.reading.ac.uk ("Scented fads" Neilski)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: explanation of the camel book code needed
  5. Keywords: sh csh perl ksh running with shells
  6. Message-ID: <nrp.721043320@reading>
  7. Date: 6 Nov 92 09:48:40 GMT
  8. References: <1992Nov5.123219.16031@unilabs.uucp>
  9. Sender: news@csug.cs.reading.ac.uk
  10. Reply-To: nrp@csug.cs.reading.ac.uk
  11. Organization: University of Reading
  12. Lines: 35
  13. Nntp-Posting-Host: angeles
  14.  
  15. chare@unilabs.uucp (Chris Hare) writes:
  16.  
  17. >On pg 216 of the camel book is a description of how to make perl run from
  18. >shells which do not support the #! construct.  I need a conscise, word by
  19. >word, letter by letter explanation, as I'm somewhat lost o how this is
  20. >interpreted by the shells, and what it all means.
  21.  
  22. I don't have the camel book (a serious shortcoming, I know) but I assume
  23. that you're referring to something like the output produced by a2p and s2p:
  24.  
  25. #!/gnu/bin/perl
  26. eval 'exec /gnu/bin/perl -S $0 ${1+"$@"}'
  27.     if $running_under_some_shell;
  28.  
  29. OK.  The first line is obviously the #! line.  The next two lines are split
  30. because shells interpret one line at a time, whereas perl goes to
  31. semicolons.  The shell comes along and sees the eval line, and executes it.
  32. This gets the perl program run with all the right arguments, and since it
  33. contains an exec the shell goes no further, but the eval makes it return
  34. the exit code produced by the perl program.
  35.  
  36. Now perl comes along and finds the two-line statement, which says "eval
  37. this if the variable $running_under_some_shell is true".  Since we're at
  38. the beginning of the program $running_under_some_shell has not been defined
  39. and so the eval is not performed, and perl goes on with the rest of the
  40. program.
  41.  
  42. Simple! (?)
  43.  
  44. -- neilski
  45.  
  46. -- 
  47. nrp@csug.cs.reading.ac.uk  \--------------------------------------------------
  48. ----------------------------\ I'm the kinda guy who likes to have
  49. his own ... special odour.  And that's why I wear ... TUNA FISH SANDWICH!
  50.