home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uunet.ca!unilabs!chare
- From: chare@unilabs.uucp (Chris Hare)
- Subject: Re: explanation of the camel book code needed
- Message-ID: <1992Nov6.113102.6581@unilabs.uucp>
- Keywords: sh csh perl ksh running with shells
- Organization: UniLabs Research Group
- References: <1992Nov5.123219.16031@unilabs.uucp> <nrp.721043320@reading>
- Date: Fri, 6 Nov 1992 11:31:02 GMT
- Lines: 52
-
- In article <nrp.721043320@reading> nrp@csug.cs.reading.ac.uk writes:
- >chare@unilabs.uucp (Chris Hare) writes:
- >
- >>On pg 216 of the camel book is a description of how to make perl run from
- >>shells which do not support the #! construct. I need a conscise, word by
- >>word, letter by letter explanation, as I'm somewhat lost o how this is
- >>interpreted by the shells, and what it all means.
- >
- >I don't have the camel book (a serious shortcoming, I know) but I assume
- >that you're referring to something like the output produced by a2p and s2p:
- >
- >#!/gnu/bin/perl
- >eval 'exec /gnu/bin/perl -S $0 ${1+"$@"}'
- > if $running_under_some_shell;
- >
- The code in the book actually is
- #!perl
- eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
- & eval 'exec perl -S $0 $argv:q'
- if 0;
-
- >OK. The first line is obviously the #! line. The next two lines are split
- >because shells interpret one line at a time, whereas perl goes to
- >semicolons. The shell comes along and sees the eval line, and executes it.
- >This gets the perl program run with all the right arguments, and since it
- >contains an exec the shell goes no further, but the eval makes it return
- >the exit code produced by the perl program.
- Yup.
- >
- >Now perl comes along and finds the two-line statement, which says "eval
- >this if the variable $running_under_some_shell is true". Since we're at
- >the beginning of the program $running_under_some_shell has not been defined
- >and so the eval is not performed, and perl goes on with the rest of the
- >program.
- Yup.
- Now what I need is a concise explanation as to this
- eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
- & eval 'exec perl -S $0 $argv:q'
- What is perl actually interpreting?
- >--
- >nrp@csug.cs.reading.ac.uk \--------------------------------------------------
- >----------------------------\ I'm the kinda guy who likes to have
- >his own ... special odour. And that's why I wear ... TUNA FISH SANDWICH!
- >
- Who was it that said that anyway??
-
- Thanks!
-
- --
- ???? --- It Always works for me! ---
- Chris Hare, UNIX Scientist Preferred : chare@unilabs.org
- Just a mild-mannered consultant by day ....
-