How to extract name/value pairs from the query string?
How to extract name/value pairs from the query string?
am 23.09.2008 17:06:16 von himanshu.garg
------=_Part_76577_7847244.1222182376210
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi,
What is the recommended module to get the name/value pairs from the
query string. Apache2::RequestRec::args comes close but there must be
something easier to use.
sub login_response {
my $r = shift;
my $args = $r->args();
...
}
Thanks,
Himanshu
------=_Part_76577_7847244.1222182376210
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi,
What is the recommended module to get the name/value pairs from the query string. Apache2::RequestRec::args comes close but there must be something easier to use.
sub login_response {
my $r = shift;
my $args = $r->args();
...
}
Thanks,
Himanshu
------=_Part_76577_7847244.1222182376210--
Re: How to extract name/value pairs from the query string?
am 23.09.2008 17:50:39 von Fred Moyer
Himanshu wrote:
> Hi,
>
> What is the recommended module to get the name/value pairs from the
> query string. Apache2::RequestRec::args comes close but there must be
> something easier to use.
>
> sub login_response {
> my $r = shift;
> my $args = $r->args();
> ...
> }
See Apache2::Request, it mirrors the CGI param api.
>
> Thanks,
> Himanshu
>
Re: How to extract name/value pairs from the query string?
am 23.09.2008 18:32:51 von John Drago
--- On Tue, 9/23/08, Himanshu wrote:
> From: Himanshu
> Subject: How to extract name/value pairs from the query string?
> To: modperl@perl.apache.org
> Date: Tuesday, September 23, 2008, 9:06 AM
> Hi,
>
> What is the recommended module to get the name/value
> pairs from the
> query string.
You could just do this:
my %args = map { my ($k,$v) = split /\=/, $_; unescape($k) => (unescape($v) } split /\&/, $r->args;
sub unescape {
# Try CGI::Simple or something else for an unescape method.
}
> Apache2::RequestRec::args comes close but
> there must be
> something easier to use.
Ha no not really. Somehow everything else must suffer (usability, debugging, intuitiveness, etc) so that we can have a *fast* web programming environment. (Yay!)
Doing those kinds of things that nobody ever really does (like, gee, parsing form contents) remains something of an oddity in the realm of mod_perl. *However* if you need to print "HELLO, WORLD!" almost as fast as a static file does...well, we've got it covered!
NOTE:: You could also check out CGI::Apache2::Wrapper on CPAN. It does everything you want, but you have to play with it to get it installed (just force install).
Best regards,
John Drago
>
> sub login_response {
> my $r = shift;
> my $args = $r->args();
> ...
> }
>
> Thanks,
> Himanshu
Re: How to extract name/value pairs from the query string?
am 23.09.2008 19:09:39 von Adam Prime
Quoting Fred Moyer :
> See Apache2::Request, it mirrors the CGI param api.
In case you dont know, Apache2::Request is part of libapreq2
(http://httpd.apache.org/apreq/). IMO, using it is the best way to
achieve what you're trying to do if you're developing for mod_perl
only. (ie you don't care if the code will run under plain CGI or not)
Adam
Re: How to extract name/value pairs from the query string?
am 23.09.2008 19:55:38 von Perrin Harkins
On Tue, Sep 23, 2008 at 12:32 PM, John Drago wrote:
> Ha no not really. Somehow everything else must suffer (usability, debugging, intuitiveness, etc) so that we can have a *fast* web programming environment. (Yay!)
While I agree that the splitting of the APIs you're referring to is
strange and confusing, this actually has nothing to do with that.
There is no parsing of form data in $r->args built into mod_perl 2
because the previous attempt at it in mod_perl 1 was broken and
considered a bad idea in retrospect. Both libapreq2 and the standard
CGI module provide robust and easy-to-use parsing of form data for
mod_perl 2.
- Perrin
Re: How to extract name/value pairs from the query string?
am 23.09.2008 20:51:34 von aw
John Drago wrote:
[...]
>
> my %args = map { my ($k,$v) = split /\=/, $_; unescape($k) => (unescape($v) } split /\&/, $r->args;
>
It's lines like this that make perl scripts small and perl great, and
give them both a bad name for Java programmers.
I'm sure someone can think of a way to strip the possible leading and
trailing spaces off the keys at the same time though.
;-)
Re: How to extract name/value pairs from the query string?
am 23.09.2008 21:10:26 von Perrin Harkins
On Tue, Sep 23, 2008 at 2:51 PM, Andr=E9 Warnier wrote:
> I'm sure someone can think of a way to strip the possible leading and
> trailing spaces off the keys at the same time though.
Please don't. Some of the reasons for using a well-tested parser like
CGI or libapreq2 are listed here:
http://perl.apache.org/docs/2.0/user/porting/compat.html#C__ r_E_gt_args__in=
_an_Array_Context
- Perrin
Re: How to extract name/value pairs from the query string?
am 24.09.2008 02:39:36 von himanshu.garg
------=_Part_83449_1324757.1222216776355
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
2008/9/23 Perrin Harkins
> On Tue, Sep 23, 2008 at 12:32 PM, John Drago wrote:
> > Ha no not really. Somehow everything else must suffer (usability,
> debugging, intuitiveness, etc) so that we can have a *fast* web programming
> environment. (Yay!)
>
> While I agree that the splitting of the APIs you're referring to is
> strange and confusing, this actually has nothing to do with that.
> There is no parsing of form data in $r->args built into mod_perl 2
> because the previous attempt at it in mod_perl 1 was broken and
> considered a bad idea in retrospect. Both libapreq2 and the standard
> CGI module provide robust and easy-to-use parsing of form data for
> mod_perl 2.
Thanks for the replies. Apache2::Request has the method I needed. Sorry that
I missed it from the docs. Using CGI.pm looked odd because I was not doing
any CGI anywhere.
Thank You,
Himanshu
>
>
> - Perrin
>
------=_Part_83449_1324757.1222216776355
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
2008/9/23 Perrin Harkins
<>
On Tue, Sep 23, 2008 at 12:32 PM, John Drago <> wrote:
> Ha no not really. Somehow everything else must suffer (usability, debugging, intuitiveness, etc) so that we can have a *fast* web programming environment. (Yay!)
While I agree that the splitting of the APIs you're referring to is
strange and confusing, this actually has nothing to do with that.
There is no parsing of form data in $r->args built into mod_perl 2
because the previous attempt at it in mod_perl 1 was broken and
considered a bad idea in retrospect. Both libapreq2 and the standard
CGI module provide robust and easy-to-use parsing of form data for
mod_perl 2.
Thanks for the replies. Apache2::Request has the method I needed. Sorry that I missed it from the docs. Using CGI.pm looked odd because I was not doing any CGI anywhere.
Thank You,
Himanshu
- Perrin
------=_Part_83449_1324757.1222216776355--