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

Hi, in my recent Fedora installation with Apache/mod_perl, somehow the following standard code in a mod_perl module doesn't work:
sub handler{ my $r = shift; my %params = $r->method eq 'POST' ? $r->content : $r->args(); #..... }
It works fine for the "POST" method. But for "GET", the $r->args() doesn't parse the key=value pair into hashes, instead, it still leaves them as "key=value" (rather than filling out the hash.) The documentation has always been that in array context, $r->args() should fill the hash.

Anyone has seen this before, or I'm missing something? Thanks.

Replies are listed 'Best First'.
Re: mod_perl query string puzzle
by ysth (Canon) on Jul 31, 2004 at 00:36 UTC
    Not sure what you mean by "key=value"? args should be getting called with list context, and should return a list of alternating keys and values. Is this what it does?
      Thanks, That's what it's supposed to do, but it's not doing that for me. For example, if the get is for: http://localhost/foo?user=abc&id=234, in array context, $r->args() should contain an array: ('user','abc','id','234'), but it contains ('user=abc&id=23'), basically it didn't split it.

        Do like this to make it happen

        my $arguments = $r->args; my %currargs = map { split("=",$_) } split(/&/, $arguments);
Re: mod_perl query string puzzle
by antirice (Priest) on Jul 31, 2004 at 17:48 UTC
    There's a note on it here. Of course it states that it was a mistake for content as well but that still works. Odd stuff. Anyway, you can use CGI or Apache::compat in the meantime (yeah, slower and all that) or you can hazard a try with libapreq2-2.03_04dev.

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1