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
|
|---|
| 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 |