Very good explanation, thanks!
But in the second example this
...
unless ( exists $abc{$parent}{$child} )
{
my %c : shared;
$abc{$parent}{$child}=\%c;
}
...
looks like an superficial assignment of
$abc{ $parent }{ $child } since immediately thereafter the reference
\%c is overwritten by a scalar. For two levels of hashing two shared hashes should be enough (
%abc and
%p).
So for this example the following minimal version should work as well:
# shared hash version.
my %abc : shared ;
my @parents = qw( a b c );
my @children = qw( 1 2 3 4 );
for my $parent ( @parents )
{
unless (exists $abc{$parent})
{
my %p : shared;
$abc{ $parent } = \%p;
}
for my $child ( @children )
{
$abc{ $parent }{ $child } = 1;
}
}
For all Perl people who got a bit confused by the example code like I was...