in reply to #!/usr/bin/perl

You're writing your script on a Windows machine, and then transferring it to a Unix/Linux machine. Right?

Because you're not transferring in ASCII mode, the line endings aren't being translated correctly, and you end up with wierd results. ...believe it or not, that's probably your problem.

Set your FTP software to ASCII mode, or use the 'dos2unix' utility to convert it after its been relocated to the runtime machine.


Dave

Replies are listed 'Best First'.
Re: Re: #!/usr/bin/perl
by Anonymous Monk on Mar 18, 2004 at 15:16 UTC
    Hi, Yes, transfers are from Windows machine to Linux but transfer are made in ASCII mode so I don't think that's the reason. In addition, the error log from apache says "premature end of script".
      Hi, Yes, you've confirmed my diagnosis: when I tested by sending a script from my Windows machine to a Linux machine in binary transfer mode (failing to convert line endings), and executed it as a CGI script, my browser told me I have an internal server error, and my apache error log told me I've had a "premature end of script" error. That's the sort of error you see, when the script terminates before the HTML header is output. I tested without the -w switch first. When I added back in the -w switch, all was ok. There is a reason for that; without the -w switch, the operating system thinks your shebang line is requesting /usr/bin/perl\r (perl\r being an invalid command name).

      The point being, that my assessment of your problem is probably accurate. If you are, as you say, transferring in ascii mode, and line endings are still failing to be converted, that's an additional problem with your FTP or PSFTP software. I'd check into that. But in the meantime, get into the habbit of, immediately following your file transfer, executing "dos2unix filename.cgi" on your remote server. It's as important as remembering to set file permissions.

      Humor us and try the dos2unix program to convert your line endings.


      Dave