From: "Bob McConnell" <r...@cbord.com>

It doesn't, the line starts with a '#' so it is ignored. You have to tell 
MS-Windows to associate .pl files with perl.exe. Then the OS does what #! was 
supposed to. But it will always use the same copy of perl.exe, so you don't get 
the ability to use different releases for different scripts.

Bob McConnell



Well, not exactly ignored.
Here is a sample zzz.pl script:

#!/usr/foo/bar -w
print "ok";

Normally, if the shebang line would be really ignored, the program should run 
fine if the program is ran using:

perl zzz.pl

But the result is:

E:\>perl zzz.pl
Can't exec /usr/foo/bar at zzz.pl line 1. 

Here is another sample script:

#!/python27/python.exe
import sys
print(sys.copyright)

And here I ran it with Perl:

E:\>perl zzz.pl
E:\>Copyright (c) 2000-2010 ActiveState Software Inc.
Copyright (c) 2001-2010 Python Software Foundation.
...

So even though the program is ran using the Perl interpreter, when it finds the 
shebang line, even under Windows, it executes the program using the interpreter 
found in that line, no matter it is not even Perl.

But this is because Perl is smarter than Python for this thing.

Here is a Perl code I put in the file zzz.py:

#!/usr/bin/perl
use CGI;
print $CGI::VERSION;

If I run it with Python, see what happends:

E:\>python zzz.py
File "zzz.py", line 2
use CGI;
^
SyntaxError: invalid syntax 

So it means that Python doesn't parse the shebang line and run the program with 
the program from it.

Which thing is better?

Perl is smarter, but it might be too smart and can create confusion for newbies.


For example, the program will give an error if it will have a shebang line with 
a non-existent path like:

#!/foo/bar/baz

But it won't give an error when using a shebang like:

#!/foo/sperlito/bar

and neither when using one like:

#!/foo/bar/baz/who/knows/others/perl/ok/zuzu

because these paths contain the string "perl" (probably).

So a shebang line like

#!perl

is enough if you want to use those switches.

Octavian


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to