我在perl中分配了一个哈希,如下所示:
my %myvers;
my @patches = ();
my @mypatches = ();
foreach my $myv ( @{$product->versions} ){
@patches = set_patches($myv->id); #get the array of patches for the version
foreach(@patches) {
push @mypatches,@{$_};
}
$myvers{$myv->name} = @mypatches;
}
$vars->{'myvers'} = \%myvers;
Run Code Online (Sandbox Code Playgroud)
当我使用以下代码访问html模板中的哈希时:
[% FOREACH key IN myvers.keys %]
alert('[% key %] is [% myvers.$key %]; ');
[% END %]
Run Code Online (Sandbox Code Playgroud)
key包含键,$ key包含上面指定的每个键的数组中元素的数量.
我无法访问数组元素的值.我怎样才能做到这一点 ?