in reply to Understanding $CGI::Q

from perldoc CGI

If you import any of the state-maintaining CGI or form-generating meth- ods, a default CGI object will be created and initialized automatically the first time you use any of the methods that require one to be present. This includes param(), textfield(), submit() and the like. (If you need direct access to the CGI object, you can find it in the global variable $CGI::Q). By importing CGI.pm methods, you can create visually elegant scripts:

But you referred to $CGI::Q before calling any of the methods noted.

Better to do away with the $CGI::Q and literally create it with:

my $q = CGI->new;
after use CGI.... Especially since you're using it in $q->param.) Or do without the object altogether, which you could, because you imported the :standard methods in your use CGI qw/:standard/; statement. But you also are NOT using it for some of your other functions, which is confusing.

I generally import nothing, create the CGI object $q and use it for all methods. It'sa less confusing to me, even though it adds line noise.

--Bob Niederman, http://bob-n.com

Replies are listed 'Best First'.
Re: Re: Understanding $CGI::Q
by daniel808 (Initiate) on Jul 15, 2003 at 23:44 UTC
    Yes yes ... that makes sense. If i put a
    param();
    call before sending $CGI::Q everything works fine.

    Thank you for pointing it out!!

    I'm actually changing the code from the imported "elegant" function interface to the object $q-> interface, as you have suggested, hence the need to handle both situations.

    Thank you all.