re: [MacPerl-WebCGI] A v B = ?
[email protected] Fri, 9 Mar 2001 12:39:21 +0900
| Newsgroups | perl.macperl.webcgi |
|---|---|
| Message-ID | <v04011701b6cdd3ee300f@[211.132.153.175]> |
[email protected] wrote: >Even placing just the -w on the shebang line causes an Internal Server Error. which means there's something fundamentally wrong with the code - it won't compile >--- start of error..... aborted due to compilation errors .....--- end of >error This is telling you the same thing - there's something fundamentally wrong with the script so it can't compile >>[shell prompt]$ tail /path/to/server/error_logs >Wish I could, but it's not my server -- I only "rent" space. Not having access to the error logs is unusual: if you can FTP into your account try using a telnet client to log on with the same connection data you use for FTP. If you _really_ can't access the server logs, you can re-direct STDERROR to STDOUT <<quoting from Debugging CGI Scripts 101 ( http://www.liquidsilver.com/scripts/debug101.html#server ) Redirect STDERR to STDOUT: open (STDERR, ">&STDOUT"); I recommend to use this only for debugging, don't leave this in your public script. Not only are other people likely to get confused when being confronted with Perl's error messages or warnings but also you won't be able to track down those errors in the server's errorlog - that can really be fatal, imagine your perfectly fine script breaks one day due to a changed environment or changed permissions of some files and you don't notice it until weeks later after finally some visitor complained. end>> >>.. using '-w' switch, use strict;........ >Okay, I'll remember that when I'm running the code on my Mac. ==Run this to fix errors :-)== #! perl-w use strict; my ($bad_habit,$good_habit,$salvation); # how to turn bad programming habits # into good ones $bad_habit="I\'ll remember that when I\'m running the code on my Mac\n"; &road_to_damascus($bad_habit); sub road_to_damascus{ my($revelation); $good_habit="I\'ll read the docs\n"; split('on',$bad_habit); $revelation=\@_; $$revelation[0]=~ s/the/any/; $salvation=join('and ',$$revelation[0],$good_habit); print $salvation,"\n"; }; ==Run this to fix errors :-)== >However, I still don't understand why the code I listed in my original >post didn't work -- it >didn't fail and it didn't error An explosion in an airless space is silent, but this doesn't mean the explosion didn't happen, you just didn't hear it. >I'm not sure that an error routine would tell me where it went wrong. It helps eliminate probable causes- this is your script B with some slight changes - why does it work? How did I figure out where it was going wrong? ==Script B== #!/usr/bin/perl-w use strict; my (@data); my ($title,$list); print "Content-type: text/html\n\n"; print "<HTML><HEAD><TITLE>$title</TITLE>"; # create table with title print <<DB; <table border="1" cellpadding="5" cellspacing="2" width="600"> <TR> <TH>ID</TH> <TH>Category</TH> <TH>Variable Name</TH> <TH>Price</TH> <TH>Name</TH> <TH>Description</TH> <TH>Item Number</TH> </TR> DB #$datafile = "Database/outlet.data"; #open (DATA, "$datafile") or die "Can't open $datafile: $!"; while (<DATA>) { next if /^$/; # skip empty lines #chomp; # remove the "line ending" #for (split(/\r/)) # find returns { # find tabs @data= split(/\t/); &row; } } close DATA; print " </table>"; sub row { # place variables into table $list =<<" ROW"; <TR> <TD>$data[0]</TD> <TD>$data[1]</TD> <TD>$data[2]</TD> <TD>\$$data[3]</TD> <TD>$data[4]</TD> <TD>$data[5]</TD> <TD>$data[6]</TD> </TR> ROW print $list; } __DATA__ database_id1 category1 variable_name1 price1 description1 item_number1 database_id2 category2 variable_name2 price2 description2 item_number2 database_id3 category3 variable_name3 price3 description3 item_number3 database_id4 category4 variable_name4 price4 description4 item_number4 ==Script B==