home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!europa.asd.contel.com!emory!sol.ctr.columbia.edu!spool.mu.edu!agate!doc.ic.ac.uk!uknet!reading!nrp
- From: nrp@csug3.cs.reading.ac.uk ("Scented fads" Neilski)
- Newsgroups: comp.lang.perl
- Subject: Re: explanation of the camel book code needed
- Keywords: sh csh perl ksh running with shells
- Message-ID: <nrp.721043320@reading>
- Date: 6 Nov 92 09:48:40 GMT
- References: <1992Nov5.123219.16031@unilabs.uucp>
- Sender: news@csug.cs.reading.ac.uk
- Reply-To: nrp@csug.cs.reading.ac.uk
- Organization: University of Reading
- Lines: 35
- Nntp-Posting-Host: angeles
-
- 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;
-
- 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.
-
- 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.
-
- Simple! (?)
-
- -- neilski
-
- --
- 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!
-