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/\&/\&amp\;/g; $retval =~ s/\</\&lt\;/g; $retval =~ s/\>/\&gt\;/g; $retval =~ s/\"/\&quot\;/g; $retval =~ s/ /\&nbsp\; /g; $retval =~ s/\n\n/\n/g; $retval =~ s/\n/\<br\>\<br\>\n/g; return $retval; }


Thanks in advance for your help! HyperZonk

In reply to Obscure variable suicide problem in autoloaded module by HyperZonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.