saintmike has asked for the wisdom of the Perl Monks concerning the following question:

Having a script like
#!/usr/bin/perl print "hello\n";
and running it from the command line using
$ perl script.pl
will use the perl interpreter perl specified on the command line to run the script, no doubt. Same holds true for
#!/some/weird/line/containing/perl print "hello\n";
but I was surprised to see that
#!/usr/local/bin/python print "python!"
when put into script.py and run via
$ perl script.py
(note the perl on the command line) will call the python interpreter without complaining! Also, a script like
#!Some Weird Comment print "perl!";
will throw an error message:
$ perl script.pl Can't exec Some at t1 line 1.
So, the deal is that if the shebang line contains the pattern perl somewhere, perl will actually run the script, whereas when it doesn't contain the perl pattern, it will try to run whatever's specified on the shebang line?

Anybody knows more about this?

Replies are listed 'Best First'.
Re: Shebang Line Weirdness
by Eimi Metamorphoumai (Deacon) on Nov 17, 2004 at 22:19 UTC
    From perlrun
    If the #! line does not contain the word "perl", the program named after the #! is executed instead of the Perl interpreter. This is slightly bizarre, but it helps people on machines that don’t do #!, because they can tell a program that their SHELL is /usr/bin/perl, and Perl will then dispatch the program to the correct interpreter for them.