I am maintaining a large CGI quoting script.
Happily, all of the relation DB stuff seems to work just
fine. However, there is one problem in the code that I have
taken some time trying to debug with no success.
The problem is this: there are some global variables in the
main program that are used for script user customization,
such as the name of the company, how many days the quote is
good for, and such like. These are used in presenting the
final version of the quote, both in HTML for user review
before submitting the quote as well as in HTML or text
format for the quote that is actually emailed to the
customer. The quote generation, display, and email are all
handled by subroutines in a separate autoloaded module
(autoloaded modules were used for various sections of the
program to reduce resource utilization, since response
times are quite acceptable as-is, but memory slamming would
create a problem).
Most of the variables appear exactly as one would expect
them to both in the web page preview and in the final quote
emailed to the customer. However, one of the variables seems
to vanish during the emailing phase for the HTML version
only.
I thought the problem might have to do with a
local
variable substitution in the email subroutine (the
$crlf variable, used for newlining, is explicitly changed
to \x0d\x0a for SMTP compatibility independent of platform
\n). However, even when this was eliminated, the problem
remains.
To summarize: why, during one subroutine pass, does the
variable exist, and during another it vanishes? Relevant
code samples follow:
In
main::
use autouse WQ_Finish => qw(EmailQuote QuotePage genHTMLquote genTextQ
+uote zoneBreak);
...
$QteExpires = '30 days';
$QtePostscript = 'Terms: Net 30 days. FOB Anytown, USA. Freight pre
+paid & add. Subject to Company terms and conditions. ' . $crlf .
'Company makes every effort to meet acceptable del
+ivery dates; however, the lead times quoted are only estimated ' .
'dates of delivery. Company disclaims liability fo
+r delays in delivery. Contact the factory after placing your ' .
'order for information regarding current availibil
+ity and shipping estimates. All lead times are ARO.';
...
QuotePage(); # Display quote for user preview
...
EmailQuote(); # Send quote to customer
In module WQ_Finish, both QuotePage and EmailQuote call
genHTMLQuote, which generates the quote in HTML format.
However, Email quote does include:
local $crlf = "\x0d\x0a";
Note that
$crlf is defined in the remainder of
the script as
"\n".
Located in WQ_Finish, genHTMLQuote includes the relevant
lines:
$retval .= '<b><i>This quote is good for ' . $main::QteExpires .
+' from the date above.</i></b><br><br>' . $crlf;
if ($main::QtePostscript ne '') { $retval .= '<font size=-1>' . m
+ain::esc2HTML($main::QtePostscript) . '</font>' . $crlf; }
Of course,
$retval is the accumulator for the
value returned by genHTMLQuote to the caller for output via
the appropriate stream. This is also the section with the
problem. When called from QuotePage,
$main::QteExpires
and
$main::QtePostscript are visible and act
correctly. When called from EmailQuote, however,
$QtePostscript vanishes. It should also be noted
that in a flat implementation of this script (no modules),
$QtePostscript is visible during both calls.
Also of note is that the call from QuotePage and from
EmailQuote occurs during separate runs of the script in both
the flat and the autoload modularized versions.
One other important code sample, in
main::
sub esc2HTML { # Convert plain text to HTML (&s, <
+s, >s, "s, double spaces, etc.)
my $retval = shift;
$retval =~ s/\&/\&\;/g;
$retval =~ s/\</\<\;/g;
$retval =~ s/\>/\>\;/g;
$retval =~ s/\"/\"\;/g;
$retval =~ s/ /\ \; /g;
$retval =~ s/\n\n/\n/g;
$retval =~ s/\n/\<br\>\<br\>\n/g;
return $retval;
}
Thanks in advance for your help!
HyperZonk