in reply to Re: Please critique this script -- Read emails and write URLs into bookmarks
in thread Please critique this script -- Read emails and write URLs into bookmarks

I'd personally avoid hard-coding a path to perl in the shebang line. [...] This allows you to change the version of Perl in the current environment and run your script under this new version. In particular, it's useful when testing how your script runs under different versions of Perl

The shebang line with a fixed interpreter does not prevent you from trying other interpreters:

./foobar.pl # <- perl from shebang perl foobar.pl # <- whatever perl is found first in $ENV{'PATH'} /home/me/bin/perl-special foobar.pl # <- a special perl /usr/local/bin/perl foobar.pl # <- common location for a local perl /usr/bin/perl foobar.pl # <- common location for system perl

perlrun has an entire chapter "Location of Perl" with recommendations:

Perl has some surprises when it comes to the shebang line, see perlrun:

Also, while most systems have /usr/bin/env, not all systems have it. Some have the env utility in /bin/env. Some systems use a symlink in one directory pointing to env in the other directory. See also http://www.in-ulm.de/~mascheck/various/shebang/#env.

env is another process that has to be started. env does not just start perl; at least, it has to parse the command line for arguments. See busybox env.c for a quite minimal implementation. Entry point is env_main(). The GNU version does much more, see GNU env.c. So using env in the #! line increases the startup time. Generally, it does not matter that much, especially on modern machines. But the overhead is not zero.

I typically start my scripts like this:
#!/usr/bin/env perl use 5.014; use strict; use warnings;

use strict is redundant here, as use VERSION with a VERSION >= 5.12.0 implies use strict. See use.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^3: Please critique this script -- Read emails and write URLs into bookmarks
by kcott (Archbishop) on Oct 13, 2016 at 16:09 UTC

    ++ Thanks for the feedback.

    I'm aware of the shebang line points you raise. Hard-coding paths to perl has, in my (>20 years) experience, many more problems than using env. Of course, there are occasions where a hard-coded path might be more appropriate.

    You quoted me as saying:

    "I typically start my scripts like this: ..."

    A more accurate quote, that conveyed the point I was making, and didn't hide the text you elided, would have been:

    "Whenever I use the '/r' modifier, I typically start my scripts like this: ..."

    If I removed the '/r' modifier, but still had code with say, //=, etc., I only need to change a '4' to a '0' (i.e. 5.0145.010); I do not need to remember to add use strict.

    — Ken