Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Getting query string with CGI::Fast

by perlfan (Vicar)
on Jul 28, 2020 at 03:26 UTC ( [id://11119876]=note: print w/replies, xml ) Need Help??


in reply to Getting query string with CGI::Fast

This is the ideal case to add:
use strict; use warnings;
Also, I think you want an if, not a while (strict/warnings would not have caught the infinite loop tho):
while ( my $q = new CGI::Fast ) { my $query = $q->param('node'); print "Content-type: text/plain\n\n"; ++$n; print "You are request number $n. Have a good day!\n"; print "query: $query\n"; $nodes{ exists $nodes{$query} ? $query : '_err' }(); print "done!\n"; }
Update:

You're not actually calling do_something in any execution path. And you don't need to use CGI in your package just to get the query option. You should be able to get it in the call to CGI::Fast and pass it to a method in your package, assuming you actually call it.

Maybe nodes{ exists $nodes{$query} ? $query : '_err' }(); needs to be nodes{ exists $nodes{$query} ? $query : '_err' }->(); ... sorry missed that it was a real hash.

Yeah you got a lot going on. Simplify it. Get rid of the package stuff, make sure your dispatching is clear, and make sure one of your terminal methods actually terminates. Hard to tell at first glance, but I still think your while is causing you some grief.

Replies are listed 'Best First'.
Re^2: Getting query string with CGI::Fast
by haukex (Archbishop) on Jul 28, 2020 at 09:21 UTC
    Also, I think you want an if, not a while

    No, that's how you're supposed to use CGI::Fast, as a glance into the documentation would have told you. The whole point of FCGI is a persistent process.

    strict/warnings would not have caught the infinite loop tho

    It would?

    (Somehow I missed the "not" in that sentence, my apologies.)
    Maybe nodes{ exists $nodes{$query} ? $query : '_err' }(); needs to be nodes{ exists $nodes{$query} ? $query : '_err' }->();

    No.

    hippo's answer is correct: The problem is there are two CGI objects in the program.

Re^2: Getting query string with CGI::Fast
by Anonymous Monk on Jul 28, 2020 at 07:09 UTC

    Thanks for pointers. I see most examples on the Internet use "while", and I'm not really sure why. Would "if" work too?

      Try it without the while loop and see what happens

        The counter does not increment when I use "if". I'm not exactly sure what the purpose of the counter is in the context of a web script. I'm totally new to FCGI. Should I be using "if" or "while"? What difference do they make after a response is received and despatched to subroutines?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11119876]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found