http://qs1969.pair.com?node_id=737553


in reply to #!/usr/bin/perl vs. -*- perl -*-

with #!/your/path/to/perl you force the use of a specific version of perl to be executed.

The line #-*- perl -*- is for someone using emacs, and can be dropped. It should force emacs to use perl syntax highlighting, even if the command itself is a shell.

The exec perl -x $0 "$@" line in the sh script executes the first perl executable found in $PATH, and would be somewhat equivalent to a header like #!env perl, which won't run on some systems. In both cases you have the risk of using modules that are not installed in either. Personally I always use the #!/my/personal/perl version.


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: #!/usr/bin/perl vs. -*- perl -*-
by Bloodnok (Vicar) on Jan 20, 2009 at 12:11 UTC
    Further to the excellent response from Tux, I tend to use the form #!/usr/bin/env perl which pulls the version of perl from your environment - this is handier if, as I have, you one, or other, or both, of the following situations...
    • Different versions of perl against which you are(required to be) testing/running your code &/or...
    • Different *NIX platform configurations on which you are testing/running your code

    The above is, of course, moot if you have to run on Windoze, where all sorts of other problems come into play e.g. as you suggest, the shebang line is ignored etc. hence work-rounds have to be used e.g. batch files containing the full perl script (incl. the shebang line) together with the -x CLI option (see perlrun).

    A user level that continues to overstate my experience :-))
Re^2: #!/usr/bin/perl vs. -*- perl -*-
by why_bird (Pilgrim) on Jan 23, 2009 at 12:35 UTC

    Thankyou, that is a very clear explanation!

    Personally I always use the #!/my/personal/perl version.

    That makes me feel much better about using it and not like I'm missing some kind of obscure 'best practice' :)

    Cheers
    why_bird
    ........
    Those are my principles. If you don't like them I have others.
    -- Groucho Marx
    .......