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

This is part of a admin program that creates a sub-dir. I want the program to die when the admin enters a dir that already exists. I get Internal Server Error instead of the 'die' message...can't figure out what's missing.:
require 'cgi.pm'; $database_location="/home/sites/www.foo.net/web/test/data/upload.db"; $dir_location = "/home/sites/www.foo.net/web/test/"; sub diedebug { local($msg) = $_[0]; $msg =~ s/^nodie//; print "$msg<br>\n"; exit(); } %in = (); &ReadParse(%in); # Parse the data submitted by the user if (($in{'company_name'}) && ($in{'password'}) && ($in{'sub_dir'})) { $dir= $in{'sub_dir'}; mkdir("$dir_location$dir", 0777) || &diedebug("<html> <center><table +CELLSPACING=0 CELLPADDING=1 BORDER=0 width=262> <tr align=center bgcolor=navy> <td><center> <table CELLSPACING=0 CELLPADDING=1 BORDER=0 width=260> <tr align=center bgcolor=navy><td bgcolor=navy colspan=2 +><font face=arial size=2 color=white><SMALL>DIRECTORY CREATION ERROR< +/small></FONT></td></tr> <tr><td bgcolor=#c0c0c0 width=60% colspan=2><font size=- +1>You are trying to create a directory that already exists! Go back +and use a different name for this particular directory.<BR></td></tr> <tr align=center><td bgcolor=navy colspan=2><font face=AR +IAL size=2 color=white><SMALL>ERROR ~ DIRECTORY NOT CREATED!</td></tr +> </table> </td></tr></table><BR></center>");
Thanks!

Replies are listed 'Best First'.
Re: Can't Seem To DIE
by stephen (Priest) on May 18, 2001 at 06:54 UTC
    You're getting the "Server Error" because you're not printing out headers in your 'diedebug' statement. A quick fix would be to:
    • Change your require 'cgi.pm' to a use CGI qw(:standard :cgi-lib)
    • Add a print header() to the top of your diedebug routine.

    I'd also look at CGI::Carp.

    stephen

      Stephen, Thanks for the tip! I added:
      print "Content-type: text/html\n\n";
      and my problems were gone. Thanks again