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

I have tried for nearly three hours now, but I have not been successfull yet..

All I want to do is to have a script.. that has input comming from both the POST function, as well as a Query String... so, i have information comming in on both $ENV{'QUERY_STRING'} and <STDIN>.

I want to take both of these strings, split them into their separate variables, and I want to convert pluses to spaces, and any hex code back into what it should be. Example %20 back into spaces or whatever they are.

How can I use CGI.pm to do this? Or, how can I do this without using CGI.pm.

Incomming Variables:
./script.cgi?action=add
From Query String: $action.
From $lt;STDIN>: $folder, $catname

Replies are listed 'Best First'.
Re: Can't get CGI.pm to work
by rucker (Scribe) on May 25, 2001 at 01:50 UTC
    Read documentation on the module and skip down to "MIXING POST AND URL PARAMETERS"
      Note that this documentation is only in recent CGI.pm

      I spent a while because I thought for sure it was in there. It turns out it's in my 5.6.0 documentation, but not my 5.005_03. (don't have the CGI versions off the top of my head)

Re: Can't get CGI.pm to work
by davorg (Chancellor) on May 25, 2001 at 01:59 UTC

    The param function handles both kinds of parameter in exactly the same way. There's no need for you to know where the parameter has come from.

    Update: Hmmm... seems I may have been misremembering. If you have both POST and GET parameters, then the POST ones come from param and the GET ones come from url_param.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Re: Can't get CGI.pm to work
by shotgunefx (Parson) on May 25, 2001 at 05:11 UTC
    Got bit by this problem a few days ago.

    From the CGI.pm documentation
    MIXING POST AND URL PARAMETERS
    $color = $query->url_param('color');

    It is possible for a script to receive CGI parameters in the URL as well as in the fill-out form by creating a form that POSTs to a URL containing a query string (a "?" mark followed by arguments). The param() method will always return the contents of the POSTed fill-out form, ignoring the URL's query string. To retrieve URL parameters, call the url_param() method. Use it in the same way as param(). The main difference is that it allows you to read the parameters, but not set them.

    Under no circumstances will the contents of the URL query string interfere with similarly-named CGI parameters in POSTed forms. If you try to mix a URL query string with a form submitted with the GET method, the results will not be what you expect.


    -Lee

    "To be civilized is to deny one's nature."
Re: Can't get CGI.pm to work
by olly (Scribe) on May 25, 2001 at 03:01 UTC
    One of the great things about cgi.pm is that all the code remains the same whether you use get, post or something else small example Let's say you have a form with the fields name and email and you inlcuded some info in the link like this http://somewhere.com/index.pl?unique_id=1092384
    to get name, email and unique id into vars you could use something like this.
    #!/usr/bin/perl -w use CGI; my $q = new CGI; my $name = $q->param( "name" ); my $email = $q->param( "email" ); my $unique_id = $q->param( "unique_id" );
    just name the thing inside the ( " " ) the same as the name of the field you want to get, that all for today!

    Imagination is more important then knowledge -Einstein-