in reply to Re: Re: CGI or DBI 'cache' problem
in thread CGI or DBI 'cache' problem

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
Unix - where you can throw the manual on the keyboard and get a command

Replies are listed 'Best First'.
Re: Re: Re: Re: CGI or DBI 'cache' problem
by slok (Acolyte) on May 13, 2002 at 06:09 UTC
    here's the problem I encounter
    using
    my ($s_off_no) = @_;
    I don't seems to be retrieving the value into the variable $s_off_no

    and using my original code
    my $s_off_no = $s_off_no;
    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.

      If you are sending the variable through to the sub

      queryresult($s_off_no);

      then this will work

      sub queryresult { my ($s_off_no) = @_; ## Do stuff }

      Other than that I would recommend reading my first post and fixing some of those other things I mentioned (at the very least you should use placeholders).



      grep
      Unix - where you can throw the manual on the keyboard and get a command