http://www.perlmonks.org?node_id=1011768


in reply to Re^2: Unwanted parameter when executing CGI scripts
in thread [SOLVED] Unwanted parameter when executing CGI scripts

will delete the "keywords" parameter in every case, i.e. regardless if it has been automatically generated by CGI.pm

You're wrong :)

I didn't read past that statement, but if you need convincing you are wrong, read the CGI.pm source

  • Comment on Re^3: Unwanted parameter when executing CGI scripts

Replies are listed 'Best First'.
Re^4: Unwanted parameter when executing CGI scripts
by Anonymous Monk on Jan 05, 2013 at 09:21 UTC
Re^4: Unwanted parameter when executing CGI scripts
by Nocturnus (Beadle) on Jan 05, 2013 at 16:24 UTC

    OK, I am sorry. You are right (no need to read the source code, only the documentation ...).

    Interestingly, the delete method seems to remove the respective entry only from $q->params, but not from $q->url_params (now guess which of the two I (have to) use). This is not documented in the CGI.pm documentation as far as I have seen.

    But that's not a big problem. I just will use one of the usual methods to remove the respective hash entry.

    Besides this, I didn't get your code to work like I want. Perhaps I have another error, but at the moment it seems that $q->keywords is empty if the script is called without any parameters, so $q -> keywords evaluates to false in this case, and the code doesn't get executed anyways.

    Regards,

    Nocturnus

      :D

      Interestingly, the delete method seems to remove the respective entry only from $q->params, but not from $q->url_params (now guess which of the two I (have to) use).

      You know what :) you don't really *have* to :) there are many options, patch CGI.pm, monkeypatch CGI, fix code ....

      Besides this, I didn't get your code to work like I want. Perhaps I have another error, but at the moment it seems that $q->keywords is empty if the script is called without any parameters, so $q -> keywords evaluates to false in this case, and the code doesn't get executed anyways.

      Yeah, if there are no keywords, don't delete keywords -- makes sense to me :)

        Well, it might make sense, but it's not what I want. As I wrote above, the problem arose when I was trying to pass parameters from the query string to another script by constructing a link which contains these parameters. I used the following method (pseudocode):

        In scriptA.pl, fill hash with all parameters from query string, using $q->url_param (and not $q->param) Do something with the hash entries Construct a new query string from the hash entries Generate a link to scriptB.pl?<new query string>

        Now, I if call

        /cgi-bin/scriptA.pl

        (without any parameters), the resulting link is

        /cgi-bin/scriptB.pl?keywords=

        i.e. there is an empty parameter "keywords" in the link which should not be there.

        This was not acceptable for me. Solving that problem turned out not to be too easy because I wanted to keep the "keywords" parameter if it had been in the query string in the first place.

        See my post below for additional misbehavior of CGI.pm and for how I solved the problem.

        Regards,

        Nocturnus