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

Greetings all, I've got a mandrake 9.1 box that I've been using as a development server. Last night I tried running a test script (hello world) to make sure my setup is working (apache 2, perl 5.8.0, mandrake 9.1 on a AMD K6 533 Mhz, 384 MB Ram) and got a syntax error... here's what I tried:
#!/usr/bin/perl -w use strict; print("Content-type: text/html\n\n"); print("Hello!");

It tells me there's a syntax error on line 4 near the first print call. After scratching my head for an hour and playing around I found that running it inline gives the same problem. I also found out that if I substitute "#!/bin/sh" for "#!/usr/bin/perl -w" and replace "print('Content-type: text/html\n\n');" with "echo Content-type: text/html\n\n" all is well. I know perl's installed in the /usr/bin/perl folder of my computer, but the typical #!/usr/bin/perl just doesn't work. Not being a fan of rpms, and never having installed Perl myself, I downloaded the latest (5.8.4), compiled and installed... and same thing. I'm sure I'm missing something simple, since I can't find similar issues on google or here. But since I'm fairly noob at Linux administration, I'm at a loss. Any thoughts?

Replies are listed 'Best First'.
Re: Perl Setup on Mandrake 9.1
by atcroft (Abbot) on Jun 15, 2004 at 16:50 UTC

    First question: What do you get when you run it from the command line?

    Second question: Did you create this file on the box, or did you upload it from a Windows machine? If the latter, did you sent it as a binary or as a text file? In the case of a text file, line endings are translated appropriately, whereas as a binary file it is sent as-is. An easy way to make sure this isn't the issue is to do the following:

    perl -p -i.bak -e "s/\r//g" filename
    This will create a backup of the file with the extension .bak, and remove the characters, if it is the case.

    Third thought: Add the line $| = 1; after your use strict; line. This will turn off output buffering, and save you headaches later.

    Are there any additional clues in the apache error_log?

    If the above don't help, then I would suggest you do an ls -l /usr/bin/perl from the command line, which will show you if /usr/bin/perl is actually a symbolic link elsewhere.

    Hope that helps....

      When I run it inline I get (paraphrasing because I won't have access to my box until tonight) "error in syntax at line 4 near 'Content-type: text/html...' Compilation aborted errors"

      In response to Q2: I created the file on the box via ssh from my windows machine.

      In response to Q3: I checked the apache log and the only message I received was "Premature end of headers" which had me spinning in circles for a while trying to figure out what my print's weren't coming through.

      I tried what you suggested as well, and it is in fact a symbolic link. It links to a second symbolic link called "perl5", which in turn links to an executable script "perl5.8.0". could this be the cause of my troubles... should I be using "#!/usr/bin/perl5.8.0"? Thanx for your reply!

      "If you're ever lost and need directions, ask the guy on the motorcycle."
have you seen the perl examples?
by chanio (Priest) on Jun 15, 2004 at 23:50 UTC
    Have you seen the perl examples like: http://127.0.0.1/cgi-bin/test.cgi?

    Later, checking the scripts at /var/www/cgi-bin and other folders, you should figure out what works and what doesn't.

    I am also having trouble with MDK 9.2 and Apache 2 + perl. But I yet, don't have much time to get it all fixed and working right...

    Check owners and groups also.

    .{\('v')/}
    _`(___)' __________________________
      Thanx for the tips. I actually found that the test.cgi had the #!/bin/sh entry along with the echo calls instead of prints to display the current system variables. I haven't tried the owners/groups though, I'll definitely try that as well as keep looking for any examples or config items I might have overlooked.

      UPDATED: I just got home from work, fired up the box and tried the file again and it worked... I can only assume rebooting did something because the first thing I did was try the file and it worked fine. I've had problems like this in the past with several programs on different OS's using this box... but irregardless it's all good now.

      If you're ever lost and need directions, ask the guy on the motorcycle.