Still learning how to do perl with plack. I have a simple app to post check boxes and other form elements. I would like to loop through check box name and value and place them in a new hash. These are obtained through a post request in Plack::Request body_parameters. Where am stuck is how to loop through the Plack::Request body_parameters. Dumper body_parameters as follows:

$VAR1 = bless( { 'c_xcode' => 'J23-H0P', 'c_ycode' => 'G12-Y4T', 'c_zcode' => 'Q87-S7B', 's_xlist' => 'T66-Y9A', 's_ylist' => 'A43-P9W', 's_zlist' => 'T71-K2L' }, 'Hash::MultiValue' );
What I would like is to convert body_parameters into a hash like this:
%form_hash = ( 'c_xcode' => 'J23-H0P', 'c_ycode' => 'G12-Y4T', 'c_zcode' => 'Q87-S7B', 's_xlist' => 'T66-Y9A', 's_ylist' => 'A43-P9W', 's_zlist' => 'T71-K2L' );

What is the best way to do this? Here's what I've tried, which I got close - it prints my desired hash to dumper, but I can't pass the \%form_hash to the foreach loop below:

my $form = $posted->body_parameters; my @k = keys %$form; my @v = values %$form; @form_hash{@k} = @v; # Dumper ( \%form_hash) works, but can't pass this to foreach; # "Experimental keys on scalar is now forbidden" when trying on # foreach my $key (sort(keys( \%form_hash ))) below.
Here is the complete snippet
#!/usr/bin/perl use strict 'refs'; use Plack::Request; use Data::Dumper; my $app = sub { my $env = shift; my $form = Plack::Request->new($env); print Dumper ( $form->body_parameters ) ; #how to convert $form->body_parameters to new %form_hash? my %form_hash; my %cb_hash; foreach my $key (sort(keys( %form_hash ))) { if ( substr($key,0,2) eq "c_" ){ my $cb_key = $key; my $cb_val = $form_hash{$key}; $cb_hash{$cb_key} = $cb_val; } } };

In reply to How to loop through Plack::Request body_parameters ? by knox

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.