<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 test.pl - 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 ./test.pl. </update2>

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

It does for me:

$ cat test.pl #!/usr/bin/env perl -wls print $x+undef; $ perl test.pl -x=5 Use of uninitialized value in addition (+) at test.pl 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.")


In reply to Re^3: How do I use 'which' in the hash-bang line? (updated x2) by haukex
in thread How do I use 'which' in the hash-bang line? by rje

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.