in reply to Re^2: How do I use 'which' in the hash-bang line?
in thread How do I use 'which' in the hash-bang line?

<update2> Sorry, I got so caught up in the point I was trying to make - that Perl scans the shebang line even when running the script as perl - that I missed the limitation that the AM pointed out below, that you are right that #!/usr/bin/env perl -w does in fact not work when invoking the script via ./ </update2>

so that #!/usr/bin/env perl -w does not work

It does for me:

$ cat #!/usr/bin/env perl -wls print $x+undef; $ perl -x=5 Use of uninitialized value in addition (+) at line 2. 5

From perlrun: 'The #! line is always examined for switches as the line is being parsed. ... Parsing of the #! switches starts wherever "perl" is mentioned in the line.'

(I'm not sure about the history of this feature at the moment.) Update: The description of this feature was in perl-5.000, although apparently the support for which options are supported there has changed, for example perl58delta says "The command-line options -s and -F are now recognized on the shebang (#!) line." or perl5100delta says "The -C option can no longer be used on the #! line." (Although as choroba pointed out and as the docs say: "It wasn't working there anyway, since the standard streams are already set up at this point in the execution of the perl interpreter.")