Perl DBI fetchall_hashref

泪湿孤枕 提交于 2019-12-04 04:22:59

No, it cannot be done using fetchall_hashref. But you can iterate over the hash values and delete the key:

delete $_->{countryiso} for values %$hash;

I had this same problem but was using multiple keys on fetchall_hashref, so I had to go deeper in the hash references. Not exactly rocket science, but here it is:

(...)          
           my @keys=('key1','key2','key3');
           my $result_ref=$sth->fetchall_hashref(\@keys);

           remove_key_values($result_ref,\@keys);
(...)


sub remove_key_values {
    my ($href_values,$aref_keys) = (@_);

    foreach my $hk (keys %$href_values) {
        foreach my $ak (@$aref_keys) {
            if ($ak eq $hk) {
                delete $href_values->{$hk};
            }
        }
        if (exists $href_values->{$hk} and ref($href_values->{$hk}) eq 'HASH') {
                remove_key_values($href_values->{$hk},$aref_keys);
        }
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!