试图在perl中对哈希的哈希进行迭代。什么';这种方法有什么错?

试图在perl中对哈希的哈希进行迭代。什么';这种方法有什么错?,perl,hash,foreach,Perl,Hash,Foreach,我试图迭代使用嵌套哈希的数据结构中的项。 为此,我想看看里面有什么钥匙 以下是我尝试过的。但是我犯了个错误 my %tgs = ( 'articles' => { 'vim' => 'about vim', 'awk' => 'about awk', 'sed' => 'about se

我试图迭代使用嵌套哈希的数据结构中的项。 为此,我想看看里面有什么钥匙

以下是我尝试过的。但是我犯了个错误

    my %tgs = (
        'articles' =>  {
                           'vim' => 'about vim',
                           'awk' => 'about awk',
                           'sed' => 'about sed'
                       },
        'ebooks'   =>  {
                           'linux 101'    => 'about linux',
                       }
    );

    foreach my $k (keys %tgs){
        print $k;
        print "\n";
        foreach my $k2 (keys %$tgs{$k}){ #<-----this is where perl is having a problem
            print $k2;
            print "\n";
        }
    }

syntax error at PATH line #, near "$tgs{"
syntax error at PATH line #, near "}"
Execution of PATH aborted due to compilation errors.
my%tgs=(
“文章”=>{
“vim”=>“关于vim”,
“awk”=>“关于awk”,
“sed”=>“关于sed”
},
“电子书”=>{
“linux 101”=>“关于linux”,
}
);
foreach my$k(钥匙%tgs){
打印$k;
打印“\n”;

对于每个我的$k2(键%$tgs{$k}){#您需要在
$tgs{$k}
周围使用大括号:

foreach my $k2 (keys %{$tgs{$k}}){ #<-----this is where perl is having a problem

$tgs{$k}
周围需要大括号:

foreach my $k2 (keys %{$tgs{$k}}){ #<-----this is where perl is having a problem