散列错误的 Perl 动态散列

Perl dynamic hash of hash errors

我正在循环查询并返回结果。我正在尝试将一个哈希添加到另一个哈希。但是运行遇到了麻烦。

my %users_data;
while($sth->fetch)
{
    $mygroup =>
    {
        'fname' => $fname,
        'lname' => $lname,
        'address' =>
        {
           'street' => $street,
           'city' => $city,
        },
        'id' => $uid,
     },
}

如何将 $mygroup 哈希添加到 %users_data 哈希?

长手会。

my %users_data = (
 'salesmanager' =>
 {
    'fname' => 'mike',
    'lname' => 'john',
    'address' =>
    {
       'street' => '123 street',
       'city' => 'Brooklyn',
    },
    'id' => 12,
 },
 'garagemanager' =>
 {
    'fname' => 'Mark',
    'lname' => 'Jones',
    'address' =>
    {
       'street' => '355 street',
       'city' => 'Brooklyn',
    },
    'id' => 13,
 },
)

只需访问目标键并为其分配新值:

my %users_data;
while($sth->fetch)
{
    $users_data{$mygroup} = {
        'fname' => $fname,
        'lname' => $lname,
        'address' =>
        {
           'street' => $street,
           'city' => $city,
        },
        'id' => $uid,
     };
}