我想删除哈希(任何深度)的元素,其中第一个键为$key [0],第二个键为$key [1]等,直到@key结束.
例如,如果@ key =(23,56,78),那么我想操纵$hash {23} {56} {78}.
我事先不知道@key有多少元素.
我一直在尝试使用以下内容:
my %the_path; my $temp=\%the_path; for(my $cline=0;$cline<=$#keys;$cline++){ my $cfolder=$keys[$cline]; $temp->{$cfolder}={}; $temp=$temp->{$cfolder}; }
但是,我不确定如何在这里操纵元素.我怎么做?
解决方法
Data::Diver就是为了这个目的而存在的.
my $last_hash = Data::Diver::Dive( \%hash,@keys[0..$#keys-1] ); if ($last_hash) { delete $last_hash->{ $keys[-1] } }