Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Unwanted parameter when executing CGI scripts

by tobyink (Abbot)
on Jan 05, 2013 at 14:00 UTC ( #1011788=note: print w/replies, xml ) Need Help??


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

You needn't test for whether $ENV{QUERY_STRING} is defined or not, because undefined things automatically have zero length.

"CGI.pm then would generate a parameter "keywords=Test", and we would remove that parameter accordingly. But that would be only the half of the way: I think that "Test" in that case should be a KEY in the parameter list which has an empty (or undefined) value."

Then you could try something like:

for ($ENV{QUERY_STRING}) { $cgi->{param}{delete $cgi->{param}{keywords}} = "" if length && !/[&=]/; }
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

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

    Thank you very much for your answer, but I just haven't got it yet. Please forgive me if I'm too stupid, but I think you are testing if the query string's length is >0, and your code only gets executed if this condition is true.

    But when calling the script without any parameters, the length of the query string is 0, and that evaluates to false, so the whole line doesn't get executed.

    Please correct me if I am wrong.

    Regards,

    Nocturnus

      Indeed, the whole line doesn't get executed. But the line doesn't need to be executed because there's no query string. Thus there will be no keywords; nothing to clean up; no work needs to be done.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

        But that was exactly my problem: If I called

        /cgi-bin/script.pl

        (i.e. without any parameters and without query string), CGI.pm behaved like if I had called

        /cgi-bin/script.pl?keywords=

        I should have mentioned that my application in this case needed to get the parameters from the query string only (GET parameters) and that it should not get the POST parameters. Thus, I was using

        $q -> url_params

        instead of

        $q -> param

        Perhaps that's the reason for the misbehavior. Furthermore, I have seen some more misbehavior (see post below), so I dumped CGI.pm; I am now parsing the query string myself.

        Regards,

        Nocturnus

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011788]
help
Chatterbox?
[choroba]: I usually do this with presentations
[Corion]: But now I think statically (re)generating the Pod tests is a saner approach, and likely I'll regenerate the tests either in Makefile.PL or from xt/ but have them live below t/
[choroba]: I keep the snippets in files of their own, and use a Makefile to syntax highlight them and insert them into slides, while also running them and inserting the output if required
[Corion]: choroba: Ooooh - I didn't think of that! I write my presentations as POD and if it "roughly" looks like Perl code, I should also syntax-check that...
[haukex]: Yes sorry I don't run them all the time, my POD tests are only run as author tests (and are excluded when I'm using Devel::Cover)
[Corion]: choroba: Hmm - no, I keep the snippets inline, but as my framework also has support for capturing output etc., maybe I should do the same...
[Corion]: haukex: Yes, that approach is sane, and it heals the fragility of Pod parsers in a nice way while still syntax-checking stuff
[choroba]: Unfortunately, none of it is online
[haukex]: I figured that POD tests make sense, but only as author tests
[choroba]: I mean, the slides are, but not the makefile with scripts to create them

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2017-02-27 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.