Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Interesting CGI.pm query_string behavior

by Hero Zzyzzx (Curate)
on Aug 13, 2002 at 16:40 UTC ( #189867=perlquestion: print w/replies, xml ) Need Help??

Hero Zzyzzx has asked for the wisdom of the Perl Monks concerning the following question:

I think I may have hit on an undocumented CGI.pm feature, or at least one that I didn't know existed.

When a POST'd form is sent to a CGI.pm enabled script, apparently you can use the query_string() method to create a state-saving parameter list, suitable to be loaded into a new CGI.pm instance to restore the parameters at a later date.

My impression was that the query_string method returned the "unprocessed query string" (quoted from the docs), which led me to believe it returned $ENV{QUERY_STRING}.

Happily, this doesn't appear to be the case. Do other folks use/abuse this feature, and is it something I can rely upon?

-Any sufficiently advanced technology is
indistinguishable from doubletalk.

  • Comment on Interesting CGI.pm query_string behavior

Replies are listed 'Best First'.
•Re: Interesting CGI.pm query_string behavior
by merlyn (Sage) on Aug 13, 2002 at 18:01 UTC
    I think your leap from "unprocessed query string" to $ENV{QUERY_STRING} is the mistake here. Since the model of CGI.pm is that it work nearly transparently for both GET and POST, I would never have imagined it to generate different results for query_string().

    So I presume, yes this is a feature, and yes, it's not going away soon.

    -- Randal L. Schwartz, Perl hacker

      This behavior does seem consistent with how the rest of CGI.pm works.

      For some reason I had it in my head that methods like query_string() and script_name() were just convenience methods for getting %ENV values, but this isn't the case. Fine with me, because this is a very nice feature. . .The docs were just a bit confusing as to what was actually returned from query_string().

      Thanks.

      -Any sufficiently advanced technology is
      indistinguishable from doubletalk.

        Indeed. It even becomes clearer when we look at the CGI.pm code. :)

        #### Method: query_string # Synthesize a query string from our current # parameters #### 'query_string' => <<'END_OF_FUNC', sub query_string { my($self) = self_or_default(@_); my($param,$value,@pairs); foreach $param ($self->param) { my($eparam) = escape($param); foreach $value ($self->param($param)) { $value = escape($value); push(@pairs,"$eparam=$value"); } } return join($USE_PARAM_SEMICOLONS ? ';' : '&',@pairs); }

        - from CGI.pm

        So it simply constructs a query string from the given name/value pairs already in the CGI object. It'll even use that far-out semicolon format if you want it to. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://189867]
Approved by jlk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2021-05-11 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (111 votes). Check out past polls.

    Notices?