home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!news.cerf.net!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Subject: Re: Details regarding the exec command
- Message-ID: <1992Dec21.202418.10520@netlabs.com>
- Sender: news@netlabs.com
- Nntp-Posting-Host: scalpel.netlabs.com
- Organization: NetLabs, Inc.
- References: <BzH641.L0J@cs.uiuc.edu>
- Date: Mon, 21 Dec 1992 20:24:18 GMT
- Lines: 66
-
- In article <BzH641.L0J@cs.uiuc.edu> schwager@mike.cs.uiuc.edu (Mike Schwager) writes:
- :
- :
- : Everyone please open their Bibles to page 143... :-)
- :
- : I'm trying to understand the "exec" call better. I notice on the
- : aforementioned page that if I do
- :
- : $shell = '/bin/csh';
- : exec $shell '-sh';
- : die "barf\n";
- :
- : Then the shell believes it is a login shell- ie, $0 must be "-". However,
- : if I do this:
- :
- : exec '/bin/csh' '-sh';
- :
- : it gives me an error, and if I do this:
- :
- : exec $shell, '-sh';
- :
- : it is not a login shell. I don't understand The Book here, nor is it clear
- : what a "multi-valued list" is. What exactly is exec'ed in the first
- : example? Why does it work, whereas if I explicitly use the string
- : '/bin/csh' it fails? Please enlighten me.
-
- List operators have what has been called the filehandle slot, and that
- nowadays I tend to call the indirect object. The distinguishing feature
- syntactically is that there is no comma separating that argument from
- the following argument. This imposes some rather tight constraints
- on what can be put into that grammatical slot. Only three things
- are allowed currently: a bare word, a simple scalar variable, or
- a block.
-
- The print operators use this to specify a filehandle. Certain other
- operators use this slot for other purposes. For instance, the
- sort operator either looks for a subroutine name or an inlined
- block of code. The exec routine looks for the name of the program
- to "really" execute.
-
- I could conceivable allow a quoted string in the filehandle slot,
- but I'm afraid that it would lead rather quickly to unreadable code,
- since it's more difficult visually to find the end of a quoted string
- than the end of a bare word, a variable name, or a block. In Perl 5
- you'll be able to say
-
- exec { "/bin/csh" } '-sh';
-
- That's also supposed to work in 4.035, but it didn't seem to when I tried it.
-
- The reason I call that the indirect object slot is by analogy between
-
- print STDOUT $foo;
-
- and
-
- give DOG $bone;
-
- And in fact, the latter would be equivalent in Perl 5 to
-
- DOG->give($bone);
-
- [Note to Raphael: yes, I agree about optimizing method lookup in the
- absence of redefinition--thanks for the suggestion.]
-
- Larry
-