我正在通过哈希引用动态创建一个下拉列表,并将数组引用传递给此方法,并希望将数组引用键与哈希引用键匹配,以便禁用匹配的键。但是由于哈希键,它过写,只有最后一个id被禁用。按照我要做的:
sub showIt {
my $hash = shift;
my $forumparentId = shift;
my $parentId = shift;
my $options = '';
my $children = $DB{mb} -> selectall_arrayref("SELECT forumid FROM table1 WHERE parentid='$parentId' ORDER BY displayorder asc",{ Slice => {} });
my $iter;
$iter = sub {
my $hash = shift;
my $indent = shift || '';
foreach my $key (sort {$a <=> $b} keys %{$hash}) {
my $hash_ref = $hash->{$key};
my $selected = $hash_ref->{forumid} == $forumparentId ? "selected=selected" : '';
my $disabled;
foreach my $child ( @{$children}){
$disabled = $child->{forumid} == $hash_ref->{forumid} ? "disabled=disabled" : '';
}
$options .= "<option value='" . $hash_ref->{forumid} . "'$selected $disabled>" . $indent . $hash_ref->{title} . "</option>\n";
if ($hash_ref->{children}){
$iter->($hash_ref->{children}, $indent . "--");
}
}
};
$iter->($hash);
return $options;
}
我该怎么做或我做错了什么?任何帮助都会很感激。