我有以下问题:我有一组对哈希的引用,我想渲染它。
$VAR1 = \{
'nice_key' => undef,
'nicer_key' => '0',
'nicest_key' => 'Miller'
};
$VAR2 = \{
'nice_key' => undef,
'nicer_key' => '0',
'nicest_key' => 'Farns'
};
$VAR3 = \{
'nice_key' => undef,
'nicer_key' => '0',
'nicest_key' => 'Woodstock'
};
...
我将其传递\@tablerows
给模板。在我做的模板里面:
[% FOREACH row = tablerows %]
<tr>
<td>[% row %]</td>
<td>[% row.nicer_key %]</td>
<td>[% row.nicest_key %]</td>
</tr>
[% END %]
-line 输出类似的[% row %]
东西REF(0x74a0160)
,但其他两行只是空白。
据我了解,row
模板中的变量必须取消引用才能调用row.nicer_key
,但使用->
or{}
会导致解析器错误。
这甚至可能还是我做错了什么?
编辑:数据结构的背景:程序执行以下操作:
- 解析包含表格的 HTML 文件
- 在解析时,将表的每一行读入一个哈希(
nice_key
s 是表的单元格)并将这些哈希存储到一个哈希的哈希中(让我们称之为tabledata
) - 做一些数据库查询并将这些添加到内部哈希中(例如
nicest_key
,原始 HTML 文件中不存在) - 以与之前相同的顺序输出一个 HTML 表格。
为了保持原始表的顺序,我tablerows
在第 2 步中用对内部哈希的引用填充了数组。
Edit2:我的意图是:
箭头表示对哈希的引用。
我如何填写这些数据
my %tabledata = ();
my @tablerows = ();
foreach (... parsing ...) {
...
$tabledata{$current_no} = ();
push @tablerows, \$tabledata{$current_no};
$tabledata{$current_no}{$row} = $value;
}
当我转储它们中的每一个%tabledata
并且@tablerows
内容对我来说似乎是正确的。