Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#!/usr/bin/perl -w versus #!/usr/bin/perl

Status
Not open for further replies.

Kirsle

Programmer
Jan 21, 2006
1,179
US
I'm wondering if anyone can clarify this for me:

When I was first learning Perl I started all my files off with a fairly basic shebang line:

Code:
#!/usr/bin/perl

My ActivePerl was installed in C:\Perl\bin\perl but Windows didn't care because it was going by file extensions, but when uploaded to *nix servers this line would work fine.

I had a web host once on a Linux server and my scripts were all giving these 500 Internal Server Errors. The files were formatted correctly and uploaded correctly, had the correct permissions to execute, but I couldn't tell what the problem was and so I searched the forums of this web hosting company. Somebody said to change the shebang line to this:

Code:
#!/usr/bin/perl -w

Sure enough, adding the -w flag allowed the script to execute just fine.

Because of that I got into the habit of always using -w in my shebang line, and every once in a while I'd have someone ask me why their CGI isn't working and I'd take a look, recommend them to add the -w and then it starts working. But the last time I actually encountered this problem was years ago.

My brother (who's not much of a programmer) was putting together a basic Perl script to e-mail him the results of a form. It wasn't working on his server so he sent me it. He had it formatted in Unicode and so Perl was complaining about unrecognized characters, so I converted it to ASCII and then Perl complained of syntax errors. Fixing them, the Perl syntax check passed just fine. So then I tested the CGI on my local Apache server running on my Fedora 9 machine, and it was giving me these server errors.

Code:
File not found: can't exec '/home/kirsle/public_html/test/member.pl'
Premature end of script headers at /home/kirsle/public_html/test/member.pl

(the error was something to that extent... my VPS web server running CentOS 5 with a custom build of Apache doesn't mind the absence of -w, and my work PC running Fedora 9 [possibly with a custom Apache] doesn't mind either, but my home PC running Fedora 9 does as does various web servers I've encountered over the years)

Why do some servers require a -w on this line and give a server error if it's not there?

-------------
Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
I have 5-10 servers running all different kinds of apache configurations and none of them require the -w, but I know my web host does. So I'm wondering if it's a apache requirement/configuration of some kind. Let us know if you find anything out :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Sounds like a Fedora 9 problem. Maybe ask on a forum that specializes in that particular OS.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top