gsd4me has asked for the wisdom of the Perl Monks concerning the following question:
Dear all, Not being an expert in new-fangled technology ("what do you mean, I'm not allowed to use assembly code?") I am trying to write a .cgi module to handle a form's data. (Primarily using a perl reference book, but that is by the by). My understanding is that I can write a cgi module to create AND handle data from a form. So I did, but I am having trouble making the (software) decision as to how to progress upon code execution. Please note that it is for historical reasons that I use HTML::Tiny and not CGI but that is not part of the problem, unless corrected here
# Start the page and form creation process as required $co = HTML::Tiny->new( mode => 'html' ); if ($co->param()) { #data returned from the form submission print "data present - to be analysed\n"; $buffer = ""; if($ENV{'REQUEST_METHOD'} eq "POST") { # POST method retrieves data by the READ command print "POST read\n"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { # GET method retrieves by accessing the relevant environment v +ariable print "Query String\n"; $buffer = $ENV{'QUERY_STRING'}; } print ("buffer=<p>$buffer</p>"); if (length ($buffer) > 0) { # Analyse the form data .... } else { print "<p>buffer size is zero<p>"; exit; } } else { # No data passed to here by a submit - create the display form tha +t is required to do so print "no data present -to display form\n"; displayForm(); }
When I run this code (on a server) I get the diagnostics saying that there is "data present - to be analysed" (as if this call is to handle the form data) but then in the next breath the diagnostics say that the "buffer size is zero". I had a minor thought that the data was somehow being 'retained' somewhere and each time that I ran the script, the 'retained' data was being retested. SO I shut everything down overnight, re-running in the morning, but the same 'problem' presents itself
Q: What is the failing in my software logic here? Have I misread/misunderstood/misinterpreted what I have read in my perl book? As always any help from the monastery would be gratefully received.
Regards ADB
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: CGI simple but frustrating fault
by 1nickt (Canon) on Mar 09, 2025 at 15:28 UTC | |
by gsd4me (Beadle) on Mar 10, 2025 at 11:29 UTC | |
by hippo (Archbishop) on Mar 10, 2025 at 12:26 UTC | |
by GrandFather (Saint) on Mar 10, 2025 at 23:55 UTC | |
by gsd4me (Beadle) on Mar 12, 2025 at 13:00 UTC | |
by GrandFather (Saint) on Mar 12, 2025 at 20:38 UTC | |
Re: CGI simple but frustrating fault
by NERDVANA (Priest) on Mar 11, 2025 at 23:33 UTC | |
by gsd4me (Beadle) on Mar 12, 2025 at 13:02 UTC | |
by hippo (Archbishop) on Mar 12, 2025 at 13:37 UTC | |
by marto (Cardinal) on Mar 12, 2025 at 13:56 UTC |