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

This perl script works in two browsers.
--------
#!/usr/bin/perl -w use CGI; my $q = new CGI; print $q->header; print "<CENTER><H1>Show me the monkey!</H1></CENTER><BR>"; print $q->end_html;
This one does NOT work in either Netscape or Konquerer.
#!/usr/bin/perl -w # CGI to select data from a SQL database use CGI; # use strict; my $co = new CGI; print $co->header; print "<CENTER><H1>CGI Environment Variables Example</H1></CENTER><BR> +"; # print $co->start_html(-title=>'CGI Environment Variables Example', # -BGCOLOR=>'black', # -TEXT=>'white'); # print $co->center($co->h1('CGI Environment Variables Example')); # foreach my $key (sort keys %ENV) { # print $co->b("$key=>$ENV{$key}"), # $co->br; # } print $co->end_html;
---------------------
But it DOES execute at the O/S, as in #perl checkvars.cgi. The error in the browser is "Premature end of script headers", Error 500. Aren't these basically IDENTICAL?!? What is REALLY sad is that I've been working on scripts taken right straight out of books today and none of them work for me accept this lame "Show me the Monkey". This last one is from the "Perl Black Book", pages 1178-1179 and all I have done it comment out lines to try to reduce it to the ridiculously simple but it still doesn't work for me! Any help, as usual is gratefully appreciated.

Andrew Lietzow

Format tweeks - dvergin 2002-05-16

Edit kudra, 2002-05-17 Changed title

Replies are listed 'Best First'.
Re: This makes NO sense!!!
by jepri (Parson) on May 17, 2002 at 04:31 UTC
    First guess: You forgot to end the script with .cgi, since by default Apache will not 'execute' perl scripts.

    Second guess: The script isn't set to execute with 'chmod a+x script.cgi'

    Third guess: You don't have the script in your cgi-bin directory, or you have removed the 'Exec' option in httpd.conf.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

      Jeremy--your second guess wins the prize!
      I guess it's only right that I should have to beat my head against the wall for a while but what's weird is that I've been running scripts on another server for a long time and those didn't give me this trouble. Guess I must have the permissions right on those, eh?

      What's weird though, is that the owner is "nobody", the httpd runs as user "nobody" and the permissions on the file were 744. Guess when you access the file with a browser Apache treats the user as not the owner and not a member of the group but puts them in the set "other"?
      Oh well. At least it is FIXED!!!
      Muchos Gracias.. Now I can take a siesta and tomorrow... GUI access to mySQL!
Re: This makes NO sense!!!
by cmilfo (Hermit) on May 17, 2002 at 04:41 UTC
    Just three more questions, your honor...

    The script executes with perl checkvars.cgi, but does it execute with just ./checkvars.cgi?
    Also, are you on a Linux/Unix server?
    Are you coding on the server or coding remotely and transfering the file?

    "Of course, your honor, I am leading the witness." If the above answers are No, Yes, and remotely (with Win32), then read on, you might be running into a ^M problem. If not, then ignore the following.

    If you've transfered the files from Win32 to Linux/Unix via FTP, there is a chance that the extra ^M used on Win32 as a line seperator followed your files over. You can test this by opening your file in VI's binary mode (vi -b file or vim -b file). If you see ^M at the end of each line, that is the problem. The magic #! can not find /usr/bin/perl^M. The main reason I'm suggesting this as the problem is that a friend at work recently had the same symptoms and a binary FTP was the culpret. Try sending the file again via FTP in ascii mode (just type ascii at the FTP prompt). Or within VI (or VIM) type :%s/^M//g To type the ^M, type <Ctl>VM.

    Cheers!
    Casey
Re: This makes NO sense!!!
by silent11 (Vicar) on May 17, 2002 at 05:36 UTC
    shouldn't you print $co->start_html();
    before you print  print "<CENTER><H1>CGI Environment Variables Example</H1></CENTER><BR>"; ?
    Netscape likes for html to start after the html tag.

    -Silent11