Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Script is not producing output.

by damian1301 (Curate)
on Mar 18, 2001 at 00:28 UTC ( [id://65187]=perlquestion: print w/replies, xml ) Need Help??

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

Well, I wrote this little program just to see if I could do it. All it is supposed to do is be like a chat...just a smaller version. Everything worked fine, with no errors or failures on my computer (Win98, 5.6.1 Perl version). When I uploaded this to the place I use to host my scripts (free.prohosting.com)I get a 500 error. I asked the webmaster if I could maybe get a hold of the error logs. He told me that they do not log the errors for free.prohosting.com only paying people.

Okay, so, whenever I get the script on the internet and run it, it gives me a 500 internal server error. So, I played around with it and now all it does is give me a captured error (you'll know what I am saying from the code) or nothing at all-- no errors (captured or 500) and nothing that I wanted to be printed (HTML, etcetera).

Well, I guess I will stop with that crap and let you see the code.

#!/usr/bin/perl -w # can't use -T because I use the rename function :( use CGI qw/param textarea textfield header submit start_form end_form/ +; #use CGI::Carp; use strict; #use diagnostics; print header; my $name = param('name'); my $said = param('talk'); my $file = 'tagbox';my $ext ='.txt'; my $full = $file.$ext; if($name && $said){ if(defined($name && $said)){ $said =~ s/`/\'/g; $name =~ s/`/\'/g; open TAG,">>$full" || errorHTML("Couldn't open the +file because $!"); print TAG $name,"`",$said,"\n"; close(TAG) || errorHTML("Shiznit"); } } my (@array, @array2,); open TAG2,"<$full" || errorHTML("Damn it!"); @array = <TAG2>; close(TAG2) || errorHTML("Fsck!"); if(@array){ #make sure there are some posts... foreach(@array){ my ($name,$said) = split/`/; push @array2,"\n$name - $said\n\n"; } if($#array2 > 24){ for my $i(1..100){ my $file2 = $file.$i; my $file3 = $file2.$ext; if(-e $file3){ next; }else{ rename($full,$file3); } } } $ENV{SCRIPT_NAME} =~ s/.*\/(.*\.(pl|cgi))/$1/i; # greediness can b +e good, occasionally print start_form(-action=>"$ENV{SCRIPT_NAME}"); print qq!<textarea name="" rows=15 cols=25 style='font-size:8pt'>! +; print @array2; print qq(</textarea>\n<Br/>); print "Name:\n",textfield(-name=>'name',-value=>$name,-maxlength=> +10,-style=>'font-size:8pt'),"<BR>\n\n"; print "Shit:&nbsp;&nbsp;&nbsp;\n","<input type=text name='talk' va +lue='' maxlength=50 style='font-size:8pt'>\n\n"; print submit(-name=>'',-value=>'Tag the thing'); print end_form; } sub errorHTML{print "<H1>Error!</h1>\n<BR>\n<BR>\n@_";}


Can anyone help?

Almost a Perl hacker.
Dave AKA damian

I encourage you to email me

Replies are listed 'Best First'.
Re: Script is not producing output.
by slayven (Pilgrim) on Mar 18, 2001 at 00:43 UTC
    creating your private logfile makes debugging much easier especially, if you don't have access to the 'real' logfiles
    use CGI::Carp qw(fatalsToBrowser); BEGIN { print CGI::header(); open (STDERR, '>>mylog.log'); }
    slay
Re: Script is not producing output.
by Falkkin (Chaplain) on Mar 18, 2001 at 01:50 UTC
    There are two possibilities here:

    1. The server-side end of things is messed up, and the script can't even run. If this is the case, you need to make sure that all the files are mode 755 (chmod 0755 as an FTP command should work on prohosting, if i remember right); make sure the script is in the appropriate cgi-bin directory, and so on. You could try installing Apache on your own computer, and playing around with stuff there, to see how the server-configuration end of things works. (This assumes you're using a unix-ish OS that supports the idea of file permissions.)

    2. Your script doesn't work well on their server. If this is the case, do the following:

    use CGI::Carp qw(fatalsToBrowser);
    Now any fatal errors (i.e. die()'s) will be sent to your browser, instead of causing an internal server error. I'm guessing this might be more reliable than your errorHTML function.
Re: Script is not producing output.
by wardk (Deacon) on Mar 18, 2001 at 11:55 UTC

    have you tried running from a commandline and passing the param's? at least you can determine exaclty what is being outputted without leaning on the error logs.

    ./scriptname name=value talk=another value

    since you are opening the TAG file for write, could very well be a permissions issue. of course, running commandline locally won't debug that issue.

    I don't see a header written in errorHTML or prior to it's potential invocation, you might want to place a header call or the equivilent Content-type line(s) to force the message to the browser.

    keep in mind it's 11pm and I have been partaking in some wonderful wine tonite...so some sort of disclaimer is more than appropriate :-)

Re: Script is not producing output.
by damian1301 (Curate) on Mar 18, 2001 at 23:01 UTC
    Thanks for all of your help.

    Over the weekend I was thinking about how this script was only producing a blank page. I started thinking about the end peice of code, near the errorHTML sub. Looking at it, I noticed that if there were no posts on the file, it would not go into the if(@array) loop at all thus printing nothing out on the screen!! So, I made some changes to the code and I am now asking for suggestions on improving it.
    #!/usr/bin/perl -w # can't use -T because I use the rename function :( use CGI qw/param textarea textfield header submit start_form end_form/ +; #use CGI::Carp; use strict; #use diagnostics; print header; my $name = param('name'); my $said = param('talk'); my $file = 'tagbox';my $ext ='.txt'; my $full = $file.$ext; if($name && $said){ if(defined($name && $said)){ $said =~ s/`/\'/g; $name =~ s/`/\'/g; open TAG,">>$full" || errorHTML("Couldn't open the +file because $!"); print TAG $name,"`",$said,"\n"; close(TAG) || errorHTML("Shiznit"); } } my (@array, @array2,); if( -e $full){ open TAG2,"<$full" || errorHTML("Damn it!"); @array = <TAG2>; close(TAG2) || errorHTML("Fsck!"); } if(@array){ #make sure there are some posts... foreach(@array){ my ($name,$said) = split/`/; push @array2,"$name - $said"; } if($#array2 > 24){ for my $i(1..100){ my $file2 = $file.$i; my $file3 = $file2.$ext; if(-e $file3){ next; }else{ rename($full,$file3); } } } $ENV{SCRIPT_NAME} =~ s/.*\/(.*\.(pl|cgi))/$1/i; # greediness can b +e good, occasionally print start_form(-action=>"$ENV{SCRIPT_NAME}"); print qq!<textarea name="" rows=15 cols=25 style='font-size:8pt' r +eadonly>!; print @array2; print qq(</textarea>\n<Br/>); print "Name:\n",textfield(-name=>'name',-value=>$name,-maxlength=> +10,-style=>'font-size:8pt'),"<BR>\n\n"; print "Shit:&nbsp;&nbsp;&nbsp;\n","<input type=text name='talk' va +lue='' maxlength=50 style='font-size:8pt'>\n\n"; print submit(-name=>'',-value=>'Tag the thing'); print end_form; }else{ print "There are no posts. Make one yourself."; print "<BR><BR>\n\n"; print start_form(-action=>"$ENV{SCRIPT_NAME}"); print "Name:\n",textfield(-name=>'name',-value=>$name,-maxlength=> +10,-style=>'font-size:8pt'),"<BR>\n\n"; print "Shit:&nbsp;&nbsp;&nbsp;\n","<input type=text name='talk' va +lue='' maxlength=50 style='font-size:8pt'>\n\n"; print submit(-name=>'',-value=>'Tag the thing'); print end_form; } sub errorHTML{print "<H1>Error!</h1>\n<BR>\n<BR>\n@_";}
    Working Test here

    Almost a Perl hacker.
    Dave AKA damian

    I encourage you to email me

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-19 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found