home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / perl / 6871 < prev    next >
Encoding:
Text File  |  1992-11-07  |  2.5 KB  |  64 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uunet.ca!unilabs!chare
  3. From: chare@unilabs.uucp (Chris Hare)
  4. Subject: Re: explanation of the camel book code needed
  5. Message-ID: <1992Nov6.113102.6581@unilabs.uucp>
  6. Keywords: sh csh perl ksh running with shells
  7. Organization: UniLabs Research Group
  8. References: <1992Nov5.123219.16031@unilabs.uucp> <nrp.721043320@reading>
  9. Date: Fri, 6 Nov 1992 11:31:02 GMT
  10. Lines: 52
  11.  
  12. In article <nrp.721043320@reading> nrp@csug.cs.reading.ac.uk writes:
  13. >chare@unilabs.uucp (Chris Hare) writes:
  14. >
  15. >>On pg 216 of the camel book is a description of how to make perl run from
  16. >>shells which do not support the #! construct.  I need a conscise, word by
  17. >>word, letter by letter explanation, as I'm somewhat lost o how this is
  18. >>interpreted by the shells, and what it all means.
  19. >
  20. >I don't have the camel book (a serious shortcoming, I know) but I assume
  21. >that you're referring to something like the output produced by a2p and s2p:
  22. >
  23. >#!/gnu/bin/perl
  24. >eval 'exec /gnu/bin/perl -S $0 ${1+"$@"}'
  25. >    if $running_under_some_shell;
  26. >
  27. The code in the book actually is
  28. #!perl
  29. eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
  30. & eval 'exec perl -S $0 $argv:q'
  31. if 0;
  32.  
  33. >OK.  The first line is obviously the #! line.  The next two lines are split
  34. >because shells interpret one line at a time, whereas perl goes to
  35. >semicolons.  The shell comes along and sees the eval line, and executes it.
  36. >This gets the perl program run with all the right arguments, and since it
  37. >contains an exec the shell goes no further, but the eval makes it return
  38. >the exit code produced by the perl program.
  39. Yup.
  40. >
  41. >Now perl comes along and finds the two-line statement, which says "eval
  42. >this if the variable $running_under_some_shell is true".  Since we're at
  43. >the beginning of the program $running_under_some_shell has not been defined
  44. >and so the eval is not performed, and perl goes on with the rest of the
  45. >program.
  46. Yup.
  47. Now what I need is a concise explanation as to this
  48.    eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
  49.    & eval 'exec perl -S $0 $argv:q'
  50. What is perl actually interpreting?  
  51. >-- 
  52. >nrp@csug.cs.reading.ac.uk  \--------------------------------------------------
  53. >----------------------------\ I'm the kinda guy who likes to have
  54. >his own ... special odour.  And that's why I wear ... TUNA FISH SANDWICH!
  55. >
  56. Who was it that said that anyway??
  57.  
  58. Thanks!
  59.  
  60. -- 
  61. ????                --- It Always works for me! ---                           
  62. Chris Hare, UNIX Scientist                  Preferred : chare@unilabs.org
  63. Just a mild-mannered consultant by day ....
  64.