Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Below is code I copied from somewhere that allows perl to be any where in the path. This works great on SUN - but returns the following error on an HP

# A comment mentioning perl to prevent looping.: A specified flag is not valid f or this command.

Anyone have any suggestions?

Thanks Robert Walkup

rdww@ti.com

#!/bin/sh -- # A comment mentioning perl to prevent looping. eval 'exec `which perl` -S $0 ${1+"$@"}' if 0; # The above 3 lines perform magic: they cause this script to be fed # to perl no matter where it is installed, provided it is in the PATH. # Unless you *really* know what you are doing, do not touch them.

Replies are listed 'Best First'.
Re: code does not work on HP
by Fletch (Bishop) on Jan 09, 2003 at 16:08 UTC

    Apparently either HP's /bin/sh or its exec() call is passing the entire shebang line and /bin/sh doesn't know what to do with the `# A comment ...' chunk. See perldoc perlrun for some other alternatives to hardcoding the path to perl in the shebang (not that there's not advantages to hardcoding it, especially if you leave multiple versions lying around your PATH).

Re: code does not work on HP
by Mr. Muskrat (Canon) on Jan 09, 2003 at 16:14 UTC
    Have you tried #!/usr/bin/env perl or the HP equivelent?