Hi again:
A different question (using the previous "well split" code, but not
regarding split() ).
Given the following routines A and B, why does A work and B does not?
The only difference between the two routines is where the "ROW" block
is placed. In example A the ROW variables appear within the "read
data loop", but in example B they are only printed within the "read
data loop" -- why does that make a difference?
#--- start of code --- A (works)
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>$title</TITLE>";
print <<DB; # create table with title
<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
my ($database_id, $category, $variable_name,
$price, $name, $description, $item_number) = split(/\t/);
print <<ROW; # place variables into table
<TR>
<TD>$database_id</TD>
<TD>$category</TD>
<TD>$variable_name</TD>
<TD>\$$price</TD>
<TD>$name</TD>
<TD>$description</TD>
<TD>$item_number</TD>
</TR>
ROW
}
}
close DATA;
print " </table>";
__END__
#---- end of code ----
---------------------------
#--- start of code --- B (does not work)
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>$title</TITLE>";
print <<DB; # create table with title
<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
$list = <<ROW; # place variables into table
<TR>
<TD>$database_id</TD>
<TD>$category</TD>
<TD>$variable_name</TD>
<TD>\$$price</TD>
<TD>$name</TD>
<TD>$description</TD>
<TD>$item_number</TD>
</TR>
ROW
$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
($database_id, $category, $variable_name,
$price, $name, $description, $item_number) = split(/\t/);
print $list;
}
}
close DATA;
print " </table>";
__END__
---------------------- end of question --------------
Thanks for any comment.
tedd
A v B = ?
| Tweet |
|
Search Discussions
-
Robinmcf at Mar 8, 2001 at 9:15 pm ⇧
Robin:?tedd@sperling.com wrotewhy does A work and B does not?I'm not sure if I understand things. You see, I can do that, but'plogies I forgot you're doing GGI on Linux, in which case-
nothing will happen -- other than a server error. I don't run this
code on my Mac -- I only write it on my Mac and run it on the server
-- am I making sense?
add
#!/usr/local/bin/perl -w
use strict;
use diagnostics-verbose;
use CGI::Carp qw(fatalsToBrowser);
to the top of your script,most internal perl generated errors will be
sent to your browser but in the event you just get a generic '500 internal
server error' change to your shell account and type
[shell prompt]$ tail /path/to/server/error_logs
which will print out the last X lines of the error log, letting you see
what caused the error. The alternative is to take the troubled section and
run it in MacPerl, which is what I prefer doing when I'm testing something
which isn't system dependant.
Either way you should get into the habit of putting these headers, they
will tell you what's going wrong immediately.
see also:
In the PODs PerlFAQ 9- Networking
on CPAN:
http://theoryx5.uwinnipeg.ca/CPAN/perl/pod/perlfaq9-full.html
the same FAQ but it has more current URLs for more info on CGI topics
HTH
Robin
-
Robinmcf at Mar 9, 2001 at 3:40 am ⇧
which means there's something fundamentally wrong with the code - it won'ttedd@sperling.com wrote:
Even placing just the -w on the shebang line causes an Internal Server Error.
compile--- start of error..... aborted due to compilation errors .....--- end ofThis is telling you the same thing - there's something fundamentally wrong
error
with the script so it can't compileNot having access to the error logs is unusual:[shell prompt]$ tail /path/to/server/error_logsWish I could, but it's not my server -- I only "rent" space.
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>>==Run this to fix errors :-)==.. using '-w' switch, use strict;........Okay, I'll remember that when I'm running the code on my Mac.
#! 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 originalAn explosion in an airless space is silent, but this doesn't mean the
post didn't work -- it
didn't fail and it didn't error
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==
-
Robinmcf at Mar 10, 2001 at 12:51 am ⇧
on my mac under MacPerltedd@sperling.com wrote:
So, where is it that you're running the code and receiving those errors?
As to issue of the script running on your mac, but not on the server as a CGI :
this may not be due to the '-w' switch a such, but if you insist on not
using it you'll find people will be reluctant to help you, (see below)
A generic 500 error check list is:
* is the path to perl correct (in the she-bang line)
* does the script have the correct permissions to run
* if you transferred it from another machine using a different OS, are you
sure the line endings are correct?
If these three steps don't solve your problem you need the error logs
Then the next thing to do is to check out the DOCs which come with all Perl
distros, because in all of the Perl NG and mailing lists, CGI related
postings are notorious for being trivial and easily solved (by using '-w',
'use strict;' and checking the 3 things above). In keeping with this, this
is the same reason why MacPerl has a separate CGI list, (it didn't always).
In the perl community in general the minute you post anything in which it's
apparent that you haven't read the docs and you haven't followed any of the
basic guidelines set out in the FAQs because you haven't read them, people
either don't reply to your posting or get downright nasty/abusive, because
they've seen the same kinds of posting over, and over again, and consider
them only marginally better than spam (but only beause the posters aren't
trying to squeeze money out of them) :~)
(from POD FAQ 9: )
My CGI script runs from the command line but not the browser. (500 Server
Error)
If you can demonstrate that you've read the following FAQs and that your
problem isn't something simple that can be easily answered, you'll probably
receive a courteous and useful reply to your question if you post it on
comp.infosystems.www.authoring.cgi (if it's something to do with HTTP,
HTML, or
the CGI protocols). Questions that appear to be Perl questions but are
really CGI ones that are posted to comp.lang.perl.misc may not be so well
received.
The useful FAQs and related documents are:
CGI FAQ
http://www.webthing.com/tutorials/cgifaq.html
Web FAQ
http://www.boutell.com/faq/
WWW Security FAQ
http://www.w3.org/Security/Faq/
HTTP Spec
http://www.w3.org/pub/WWW/Protocols/HTTP/
HTML Spec
http://www.w3.org/TR/REC-html40/
http://www.w3.org/pub/WWW/MarkUp/
CGI Spec
http://www.w3.org/CGI/
CGI Security FAQ
http://www.go2net.com/people/paulp/cgi-security/safe-cgi.txt
-
Tedd at Mar 10, 2001 at 7:10 pm ⇧
Robin:?tedd@sperling.com wrote:on my mac under MacPerl
So, where is it that you're running the code and receiving those errors?
As to issue of the script running on your mac, but not on the server
as a CGI :
this may not be due to the '-w' switch a such, but if you insist on not
using it you'll find people will be reluctant to help you, (see below)
I'm not refusing to use the -w option nor have I said that I refuse
to do so. Apparently, I have not been clear as to the problems I
experienced and my inquiries regarding as to its use -- for that I
apologize.
As for reading FAQ's -- I read everything I can and all referenced
me. The reference you provided is one that I was not aware, but shall
use. I do find that there is a vast amount of information on Perl and
as such, I am simply overwhelmed by its shear volume. I am probably
like many others in that not everything I read is immediately
comprehended - sometimes the elusive nature of the syntax evades my
immediate acknowledgement. Furthermore, I have found errors in some
reference material which has lead me astray and it takes a while to
sort things out.
Granted, I have purpose and have probably leaped past some of the
introductory aspects of the language in an attempt to fulfill my
goal. But from my perspective, it's hard to sort out what is actually
introductory and what is not -- considering the shear volume of the
reference material. So, I am sure there remains a significant amount
of introductory material for me to consider -- that in itself is a
problem. But, I have not intentionally taken advantage of other's
time beyond what I would consider to be unreasonable. I am simply
trying to understand and thought that this list was a forum to assist
me. To me, the questions I post are not trivial -- but apparently, I
am alone in that view. It's almost humorous in that some things are
so obvious to some, but not others.
In any event, I consider myself forewarned. You have been very
helpful, gracious and polite in pointing out my failing to read the
relevant references. In the future I shall make very effort to
research all sources of information available to me before posting
another question to this list.
I thank you for your time and guidance.
tedd
Related Discussions
Discussion Navigation
| view | thread | post |
Discussion Overview
| group | macperl-webcgi
|
| categories | perl |
| posted | Mar 7, '01 at 11:59p |
| active | Mar 10, '01 at 7:10p |
| posts | 7 |
| users | 2 |
| website | sourceforge.net... |
