Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: #!/usr/bin/perl vs. -*- perl -*-

by Tux (Canon)
on Jan 20, 2009 at 11:42 UTC ( #737553=note: print w/replies, xml ) Need Help??

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' :)

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://737553]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2023-06-08 22:45 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (35 votes). Check out past polls.