perl shebang needs -w to work???

My perl script wouldn't work, coming up with server error until I put the "-w" on the end of the shebang. Now it works perfectly, no errors.

Why???

4 Replies

-w is very similar to the "use warnings" option, and you're generally expected to always use it. In fact, the man page for PERL lists as a bug that -w is not mandatory (implying that the PERL developers feel that it should be).

I'm not a PERL developer, but my guess is that omitting -w treats warnings as errors, hence why your script won't run. But again, that's just a guess. Ideally, you'd have no warnings, and so there'd be no difference between using -w or not.

@ybop:

My perl script wouldn't work, coming up with server error until I put the "-w" on the end of the shebang. Now it works perfectly, no errors.

Why???

Can you post the exact error message for even a simple test case, please? It would be very helpful in assisting us with assisting you in figuring this out. :-)

@ybop:

My perl script wouldn't work, coming up with server error until I put the "-w" on the end of the shebang. Now it works perfectly, no errors.

Why???

This is a guess:

You wrote the script (or transferred or it something) through a Windows machine and so you have CRLF line endings. This means your first line was really

!/usr/bin/perl^M

(with the ^M meaning a carriage-return).

Of course there is no program /usr/bin/perl^M and so the OS refused to run it.

By adding "-w" you turned it into

!/usr/bin/perl -w^M

and this ran OK (perl ignored the ^M).

If this is your problem then "dos2unix" will fix your file. You should then look into how you transfer your programs and ensure you have the correct line endings for unix (just a LF).

Thank you! That was it :) I wrote the script about 10 years ago but in the process of transferring it to a new host, it seems an errant CR found it's way where it oughtn't.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct