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

If I were to use this, old way of reading a form:
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
$query would contain the data posted to the form, in a certain order... Would I have the same order by putting them this way:

foreach my $f (param()) { $query .= "&" if $query && $query ne ""; $query .= "$f=" . param($f); }

I just need to keep the same format as the orginal.

thx,
Richard

Replies are listed 'Best First'.
Re: CGI.pm and QUERY_STRING
by tachyon (Chancellor) on Apr 07, 2004 at 03:31 UTC

    First CGI.pm and CGI::Simple *do* maintain the supplied order of params when you iterate over the list so the simple answer is yes.

    However you can't depend on the order the params are passed in, there are/used to be some browser quirks. Next you can just get the original (or whatever is in your current object) query string using the query_string() method in CGI.pm. Your sample code is broken as CGI.pm will URL decode the param keys/values and if you want a valid query string you need to URL encode the keys and values again (as noted there is a method to handle all the details for you) Finally any app that depends on the supplied order is at best fragile, if not actually broken.

    cheers

    tachyon

      I just need it to use with LWP, which the site that is posting the data to me, wants me to post it back, exactly as they sent it... and add a command to the end of the query so it knows it's validating the info.

      I guess I could just stick with their "sample" code, although it does use the old methods.

      thx,
      Richard
        Why not just do your test on the params and then send them back:
        get("http://their.domain/script?". $ENV{QUERY_STRING}. "&my_param=whatever");

        ?

        cLive ;-)