I want to run perl -w
using env
. That works fine on the command line:
$ /bin/env perl -we \'print \"Hello, world!\\n\"\'
H
The hash-bang isn't a normal shell command-line, the parsing and white-space handling is different - that's what you've hit. See:
Basically many/most unixes put all of the remaining text after the first space into a single argument.
So:
#!/bin/env perl -w
is the equivalent of:
/bin/env "perl -w"
so you need to handle any options to the perl interpreter in some other fashion. i.e.
use warnings;
(as @Telemachus)
Instead of -w
use the warnings pragma (for modern versions of Perl):
#!/bin/env perl
use warnings;
use strict;
It's worth noting that Mac OS X interprets characters after the shebang as arguments, so on OS X, the following will work:
#!/usr/bin/env perl -wT
enter code here
However, since one of the points of using #!/usr/bin/env is to foster cross-platform compatibility, it's probably best not to use that syntax even if you're on a Mac mostly.
I thought it might be useful to bring up that "-w" is not the same as "use warnings". -w will apply to all packages that you use, "use warnings" will only apply lexically. You typically do not want to use or rely upon "-w"