嘗試在Perl中創建嵌入哈希,並使用CGI表單中的條目進行填充。在Perl中彈出嵌套哈希數據結構的問題
這裏是一個片段:
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 ...
};
}
但後來當我嘗試轉儲數據結構進行檢查:
print $q->header(-type=>'text/plain');
print Data::Dumper->new([\%data],[qw/data/])->Indent(3)->Quotekeys(0)->Dump;
我得到的是一個空的數據結構!
$data = {};
我明顯做錯了什麼,但我無法弄清楚什麼...想法?
這是不是很清楚你說什麼要做。 – 2012-01-05 21:19:33
將'my%data'更改爲'我的$ data = {}' – ccheneson 2012-01-05 21:22:53
它沒有工作......任何其他建議? – daniel0mullins 2012-01-05 21:28:22