Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading Perl线程::用于嵌套数据结构的共享线程_Multithreading_Perl_Hash - Fatal编程技术网

Multithreading Perl线程::用于嵌套数据结构的共享线程

Multithreading Perl线程::用于嵌套数据结构的共享线程,multithreading,perl,hash,Multithreading,Perl,Hash,现在,我必须像上面那样,为每个子级别的散列显式地创建一个散列引用 有更好的方法吗 另外,如果我没有创建散列引用,那么我会得到一个“共享标量的无效值”错误,因为我试图将其用作散列。自动激活会导致 # thread::shared only allws a single level of shared structure # needs a explicit hash creation for nested data structures my %counts : shared = ();

现在,我必须像上面那样,为每个子级别的散列显式地创建一个散列引用

有更好的方法吗

另外,如果我没有创建散列引用,那么我会得到一个“共享标量的无效值”错误,因为我试图将其用作散列。

自动激活会导致

# thread::shared only allws a single level of shared structure
# needs a explicit hash creation for nested data structures
my %counts     : shared = ();

foreach my $state (%known_states) {
    # COUNTS
    unless (exists $counts{build}) {
        my %cb : shared;
        $counts{build} = \%cb;
    }
    $counts{build}{$state} = 0;

}
表现得像

$counts{build}{$state} = 0;
为了便于阅读,我们把它改为两行

( $counts{build} //= {} )->{$state} = 0;
但就像你说的,我们需要一个共享哈希

$counts{build} //= {};
$counts{build}{$state} = 0;
可以添加以下内容以确保不会意外激活非共享变量:

$counts{build} //= &share({});
$counts{build}{$state} = 0;
no autovivification qw( fetch store exists delete );