in reply to CGI or DBI 'cache' problem
my $s_off_no = $s_off_no;
Besides that, I'd expect to see something like:
Perhaps you could post a follow-up with your form-handling code.my $s_off_no = $cgi->param('s_off_no');
|
|---|
| Replies are listed 'Best First'. | ||
|---|---|---|
|
Re: Re: CGI or DBI 'cache' problem
by slok (Acolyte) on May 13, 2002 at 04:41 UTC | ||
| [reply] [d/l] | |
by grep (Monsignor) on May 13, 2002 at 05:06 UTC | ||
Ok... to handle the problem chromatic and I pointed out do this. queryresult($s_off_no);This is good you loaded the $s_off_no variable into the @_ array Here is the problem my $s_off_no = $s_off_no;^ Here you do not touch the var you loaded into @_. You just take the (lexical scoped to the main package) $s_off_no and assign it to (lexical scoped to the sub) $s_off_no (You hope) What you should really be doing is my ($s_off_no) = @_;This insures there is no ambiguity to where the the var is coming from. Honestly, I do not know if the perl interepets the RHS as the sub scoped lexical of your statement because I have never done this, but it not only introduces ambiguity to you code (possible problems for the interpreter) it also makes it difficult to read for other people (including youself in a month). PS: as a side node you are loading all the CGI functions into you main namespace. use CGI ':standard';But you use the OO interface my $q = new CGI;you should be able the ditch the ':standard' on the use CGI; grep
| [reply] [d/l] [select] | |
by slok (Acolyte) on May 13, 2002 at 06:09 UTC | ||
using I don't seems to be retrieving the value into the variable $s_off_no and using my original code while i get the value, my query only works one time. after which, even though I am submitting different query, it is still executing the previous query. | [reply] [d/l] [select] | |
by grep (Monsignor) on May 13, 2002 at 07:01 UTC | ||
|
Re: Re: CGI or DBI 'cache' problem
by slok (Acolyte) on May 15, 2002 at 11:30 UTC | ||
What I did is to shift these codes and any other validation codes into the subroutine instead of leaving it in the "main". the 'caching' goes away, but I do not know why. thanks | [reply] [d/l] | |
by chromatic (Archbishop) on May 15, 2002 at 14:39 UTC | ||
I think the problem is that you're running afoul of an optimization. Since it's expensive to allocate and deallocate memory, Perl often reuses and rarely clears the pads attached to subroutines. That means that names and values stick around. Normally, this isn't a problem. What your code did was to assign the value of the global $s_off_no (in the package symbol table) to the lexical $s_off_no (in the pad attached to the sub) on the first invocation. On subsequent calls, $s_off_no on the right hand side resolves not to the global but to the lexical left over from the first call. If you pass arguments to the sub, you'll always end up with fresh values in the pad. It could be considered a bug, but this is a really good corner case. (note: this is speculation on my part, with the appropriate amount of hand-waving) | [reply] [d/l] [select] | |