Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Problems with 500 server errors

by Anonymous Monk
on Jun 05, 2001 at 16:28 UTC ( #85781=perlquestion: print w/replies, xml ) Need Help??

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

This code gets a 500 server error and I have reviewed it many times and can not find the error can you please help.
#!/usr/local/bin/perl open (USERFILE, "/user/test"); for $line (<USERFILE>) { if (index $line, "password" > -1) { $PasswordLine=$line; } if (index $line, "minatt" > -1) { $MinattLine=$line; } if (index $line, "maxatt" > -1) { $MaxattLine=$line; } if (index $line, "exp" > -1) { $ExpLine=$line; } if (index $line, "gold" > -1) { $GoldLine=$line; } } close USERFILE ; sub getpassword { my $start= index $PasswordLine, ":" + 2; result substr $start, length $line; } sub getminatt { my $start=index $MinattLine, ":" + 2; result substr $start, length $line; } sub getmaxatt { my $start= index $MaxattLine, ":" + 2; result substr $start, length $line; } sub getexp { my $start= index $ExpLine, ":" + 2; result substr $start, length $line; } sub getgold { my $start= index $GoldLine, ":" + 2; result substr $start, length $line; } getgold;

Replies are listed 'Best First'.
Re: Problems with 500 server errors
by mpolo (Chaplain) on Jun 05, 2001 at 16:39 UTC
    Lots of 500 errors stem from file permissions. Make sure your USERFILE is read/writable by the user that gets assigned to httpd (normally you need to make it 666 on a *nix box. The script itself has to be executable, but you probably know that.

    The other most common thing would be that your program prints anything before it prints a valid HTTP header. In this case your program doesn't print anything at all....

    Two good sources for debugging this are (1) the http error log on your server. (Location varies from server to server -- RedHat installs it in /var/log/httpd/error_log) and (2) the Carp module. While you are in a debugging phase, it can help enormously to put

    use Carp qw/fatalsToBrowser/;
    at the top of your program. This sends any run-time errors to the browser window. Compiler errors will have to be seen in the error log, though.
Re: Problems with 500 server errors
by Asim (Hermit) on Jun 05, 2001 at 16:50 UTC

    There are a number of issues with this code that I see. Let me make some general suggestions, based upon the above code:

    1. use strict and the -w line in your code, and make sure the line that starts with #! points to where perl is actually installed on the web server.
    2. Run this program, with all the above, from the command line, and see if it works.
    3. Find a good, solid book and/or online tutorial on the basics of CGI programming. I'll recommend Ovid's use CGI or die; and his CGI course for starters.

    Part of the reason I'm doing this as a general overview is that I don't know what OS you're using, or what web server you're using. As far as the code itself, you've given it to us w/o the file to test it on, and it's not obvious from the code what the file is, or the structure it has. That all makes it hard to debug.

    Please read through the above, and post back with more details if you're still stumped.

    ----Asim, known to some as Woodrow.

Re: Problems with 500 server errors
by Beatnik (Parson) on Jun 05, 2001 at 21:41 UTC
    You need a HTTP header...

    Correction: you NEED a HTTP header...
    use CGI qw/:standard/; print header;
    Check CGI for more info

    ... Quidquid perl dictum sit, altum viditur.
Re: Problems with 500 server errors
by Zaxo (Archbishop) on Jun 05, 2001 at 16:46 UTC

    I haven't reviewed your code in detail, but it jumps right out that there is probably no /user directory on the system, and if there were you probably wouldn't have write permission. A relative path like "user/test" may be what you mean.

    If your user/test is executable, be aware that there is a system util called 'test'. You will break shell scripts if your test gets called instead. You will become confused if the system 'test' gets executed in rather than yours.

    After Compline,

Re: Problems with 500 server errors
by Anonymous Monk on Jun 13, 2001 at 07:30 UTC
    all the variables like $PasswordLine have the value of the $GoldLine. so $GoldLine is the only correct one.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://85781]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2020-10-20 19:35 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (210 votes). Check out past polls.