Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

parse multipart/form-data into a hash structure

by pg (Canon)
on Oct 04, 2005 at 22:53 UTC ( #497428=snippet: print w/replies, xml ) Need Help??

This sub takes a HTTP::Request, and returns a hash data structure that contains all form fields. If you have a form field named "blah", and the returned hash is stored in $form_data, then you can get the value for blah through $form_data->{"blah"}.

The asumption is that the form use multipart/form-data encoding. The code is something I use, and not heavily tested with differnt situations.

sub analyze_request {
    my $req = shift;
    my $form_data;
    for my $part ($req->parts()) {
        if (my $content_disposition = $part->headers->header("Content-
+Disposition")) {
            if ($content_disposition =~ /^form-data; name=\"(.*?)\"/) 
                $form_data->{$1} = $part->content();
    return $form_data;
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://497428]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2016-10-28 20:19 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (387 votes). Check out past polls.