Path: utzoo!utgpu!water!watmath!clyde!bellcore!decvax!ucbvax!agate!aurora!amelia!ames!elroy!devvax!lwall From: lwall@devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.sources.d Subject: Re: Using perl without "#!" Message-ID: <1291@devvax.JPL.NASA.GOV> Date: 11 Feb 88 17:54:34 GMT References: <184@ateng.UUCP> Reply-To: lwall@devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA. Lines: 38 In article <184@ateng.UUCP> chip@ateng.UUCP (Chip Salzenberg) writes: : ...here is a way to fake it without "#!": use one of the commands that : is the same under sh and perl: "eval". Put this at the top of each perl : script: : : eval "exec /bin/perl $0 $*" : if (0); : : So when sh sees the first line, it executes it; then when perl sees it, : it passes the syntax check, but the if(0) keeps it from being executed. That's wondrous fair, Chip! I'm still grinning. I'd suggest a few improvements, however. First, the parens around the 0 are unnecessary. Second, why not make it self-documenting: eval "exec /bin/perl $0 $*" if $running_via_sh; Third, rather than putting it *instead* of #!/bin/perl, put it after that line if your sh understands # comments. That way the script is more portable. Incidental-like, that /bin/perl reminds me of a complaint that I've been getting from some people--why a2p always puts #!/bin/perl in the front of its output when in Configure you've told it to put perl into some other directory. The answer is that I want people to be able to write somewhat portable perl scripts. I intended that you should always be able to get to /bin/perl on any machine, even it is just a symbolic link to where the real perl is stored. If you look carefully at the Makefile you'll see that that is what it tries to do. At least for systems with symbolic links, this gets us standardization without forcing people to use much storage in the root partition. So a2p will continue to spit out #!/bin/perl. Now I just have to decide if a2p should put the above eval in for systems without #!. I do feel sorry for all victims of NIH. Larry Wall lwall@jpl-devvax.jpl.nasa.gov