Placing a precompiled regular expression inside two different hashes listed:
my @list = ();
my $regex = qr/ABC/;
push @list, { 'one' => $regex };
push @list, { 'two' => $regex };
use Data::Dumper;
print Dumper(\@list);
I would expect:
$VAR1 = [
{
'one' => qr/(?-xism:ABC)/
},
{
'two' => qr/(?-xism:ABC)/
}
];
But instead, we get a circular link:
$VAR1 = [
{
'one' => qr/(?-xism:ABC)/
},
{
'two' => $VAR1->[0]{'one'}
}
];
This will happen with undefined nested hash links and shallow copied ones $regex.
My guess is that the main reason is that precompiled regular expressions are actually links, and links within the same list structure are compacted as optimizations (\ $ scalar behaves the same way). I do not quite understand the usefulness of this (presumably the link to the link has the same amount of memory), but maybe there is a reason based on the internal representation
? ? , , , GC , . , , , MongoDB segfault (. https://rt.cpan.org/Public/Bug/Display.html?id=58500)