Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7018373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:02:28+00:00 2026-05-27T23:02:28+00:00

Trying to create a nested hash in Perl that is populated with entries from

  • 0

Trying to create a nested hash in Perl that is populated with entries from a CGI form.

Here is a snippet:

my $section = $q->param('section') || undef;
my %data;

if($section) {
    my $prod1part  = $q->param('prod1part') || undef;
    my $prod2part  = $q->param('prod2part') || undef;
    my $prod3part  = $q->param('prod3part') || undef;

    my $prod1name  = $q->param('prod1name') || undef;
    my $prod2name  = $q->param('prod2name') || undef;
    my $prod3name  = $q->param('prod3name') || undef;

    my $prod1price = $q->param('prod1price') || undef;
    my $prod2price = $q->param('prod2price') || undef;
    my $prod3price = $q->param('prod3price') || undef;

    my $dealprice  = $q->param('dealprice') || undef;

    my $dealtype   = $q->param('dealtype') || undef;

    my $id = &generateID();

    #GENERATE DATA STRUCTURE FOR PDF
    $data = {    product1  => { part  => $prod1part,
                                name  => $prod1name,
                                price => $prod1price,
                              },
                 product2  => { part  => $prod2part,
                                name  => $prod2name,
                                price => $prod2price,
                              },
                 product3  => { part  => $prod3part,
                                name  => $prod3name,
                                price => $prod3price,
                              },
             ... and so on ...
            };
}

But then when I attempt to dump the data structure to check it:

print $q->header(-type=>'text/plain');
print Data::Dumper->new([\%data],[qw/data/])->Indent(3)->Quotekeys(0)->Dump;

All I get is an empty data structure!!!

$data = {};

I’m obviously doing something wrong, but I can’t figure out what… Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:02:29+00:00Added an answer on May 27, 2026 at 11:02 pm

    What you have:

    $data = { 
        product1  => { part  => $prod1part,
    

    What you probably meant:

    %data = (
        product1  => { part  => $prod1part,
    

    That being said, you are repeating yourself quite a lot. Try this instead:

    my $section = $q->param('section');
    my %data;
    
    if($section) {
      for my $item_id ( 1..3 ){
        my $item_data = $data{ 'product' . $item_id } = {};
        for my $attr (qw'part name price'){
          $item_data->{ $attr } = $q->param( 'prod' . $item_id . $attr );
        }
      }
    
      my $dealprice  = $q->param('dealprice');
      my $dealtype   = $q->param('dealtype');
    
      my $id = generateID();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create nested array's dynamically from a string that has been
I am trying to create a nested JSON that has data from various db
[Python 3.1] I am trying to create a hash for a container that may
I am trying to create a form with Sencha Touch that will create a
I'm trying to create a nested form but I'm missing something as keep getting
I'm trying to create a horizontal list from a nested list markup, as an
I'm trying to create a JSON object on form submit to pass to Perl.
I am trying to create a nested form using formtastic. I've included my code
I am trying to create form that contains another model in rails. I have
I'm trying to create a complex (from my opinion) form, but the process is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.