Path: utzoo!mnetor!uunet!husc6!purdue!umd5!uvaarpa!mer6g From: mer6g@uvaarpa.virginia.edu (Marc E. Rouleau) Newsgroups: comp.sources.d Subject: Perl: Hacking The !# Simulation Message-ID: <67@uvaarpa.virginia.edu> Date: 28 Apr 88 14:08:29 GMT Reply-To: mer6g@uvaarpa.Virginia.EDU (Marc E. Rouleau) Organization: University of Virginia, Charlottesville Lines: 33 References: While the simulation of the #! hack is a very clever, useful idea (thanks, Chip!) for those of us who suffer with the more primitive dialects of UNIX :-), I'd like to suggest an improvement. As you may recall, the final notion was to place the following lines in every perl script immediately below the #!/bin/perl line: eval "exec /bin/perl $0 $*" if $running_via_sh; This works great as long as $0 contains an complete path to the perl script; however, such is frequently not the case. In particular, the above solution fails whenever the shell uses the $PATH environment variable to find the perl script. With this in mind I'd like to propose that something like the following be done instead: eval "exec /bin/perl `/usr/local/ksh -c \"whence $0\"` $*" if $running_via_sh; If ksh(1) isn't available on your system, I think csh(1) has a built-in called "which" which functions like ksh's "whence". The only folks still left in the cold are those who have only the Bourne shell (sh(1)). I think the only solution for sh-only folks would be an option to perl (perhaps -S?) which requests that it use $PATH if it exists in the evironment or else some compiled-in default to determine the location of its script. Comments? -- Marc Rouleau