This is stolen and modified from CGI.pm's ReadParse method: It'll work fine unless there are multiple query params with the same name.
sub ReadParse { my $in = shift; @in = split(/&/,$in); foreach $i (0 .. $#in) { # Convert plus's to spaces $in[$i] =~ s/\+/ /g; # Split into key and value. ($key, $val) = split(/=/,$in[$i],2); # splits on the first =. # Convert %XX from hex numbers to alphanumeric $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; # Associate key and value. \0 is the multiple separator $in{$key} = $val; } return \%in; } my $data = ReadParse('a=7&b=1&text=Some+text'); print $data->{text}, "\n"; # prints 'Some text'
PS: you want those brackets in your question to be curlies, not square brackets. Otherwise you'll get an array ref, not a hash ref.

PPS: You mentioned that CGI and Apache::Request modules both contained the functionality to do this. When that's the case, it's usually helpful (and a learning experience) to jump into the code for those modules and try to extract only the parts that you need. But then again, reinventing the wheel yourself is also a good learning experience too. ;) Take your pick!

blokhead


In reply to Re: Parsing form post (content) by blokhead
in thread Parsing form post (content) by mp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.