Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!lll-tis!ames!elroy!devvax!lwall From: lwall@devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.sources.d Subject: Re: Perl: Hacking The !# Simulation Message-ID: <1950@devvax.JPL.NASA.GOV> Date: 3 May 88 20:23:54 GMT References: <67@uvaarpa.virginia.edu> <394@dsinc.UUCP> <75@uvaarpa.virginia.edu> Reply-To: lwall@devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA. Lines: 42 In article <75@uvaarpa.virginia.edu> mer6g@uvaarpa.Virginia.EDU (Marc E. Rouleau) writes: : >>eval "exec /bin/perl `/usr/local/ksh -c \"whence $0\"` $*" : >> if $running_via_sh; : >> : >>The only folks still left in the cold are those who have only the Bourne : >>shell (sh(1)). : > : >Even those are not left out in the cold, they can use the type internal : >command which finds the executable. : : But "type" prints its output in "whence -v" format, so further processing with : something like expr(1) would be necessary. I know, let's have a contest to see how many processes we can use up before actually executing the script... : >Now we need a way to have it automatically determine the shell type and use : >the appropriate command if needed. : : I think this is all becoming much too complicated. The original idea is : relatively elegant and simple, and, in the absence of #! for System V, it : seems like the next best thing; _however_, I really think the path-searching : complexity oughta be implemented within perl. : : What if we could do something like this: : : eval "exec /bin/perl -S $0 $*" : if $running_via_sh; : : The -S switch would cause the script file to be searched for either using an : algorithm implemented within perl (best case) or else by running a program : (ksh, csh, sh) the path to which is configurable and compiled in (acceptable : case). Let's go with the best case. I've hacked -S into version 2.0, so you guys can stop squabbling now. The -S switch will cause a path search if the filename doesn't begin with '/'. Takes about 20 lines of code to do it right. Hacking #! into the kernel wouldn't have been that much harder... :-) Larry