This isn't exactly your question, but... if you're actually building the data structure in that fashion, you might consider a cleaner "literal" syntax:
#!/usr/bin/perl
use strict;
use warnings;
my %VAR = (
SCALAR => 'test scalar',
ARRAY => [
'test array',
],
HASH => {
NAME => [
'test hash array 1',
'test hash array 2',
{
SOMEHASH => 'test hash array hash 1',
ANOTHERHASH => 'test hash array hash 2',
},
],
},
);
The main two reasons are readability and autovivification bugs. That's not incorrect perl, but it can lead to hard-to-debug issues, such as accidentally typing:
$VAR{HASH}{NAME}[1] = "test hash array 1";
$VAR{HASH}{NAME}[2] = "test hash array 2";
$VAR{HASH}{NAME}[2] = "test hash array 3";
$VAR{HASH}{NAME}[4] = "test hash array 4";
instead of
$VAR{HASH}{NAME}[1] = "test hash array 1";
$VAR{HASH}{NAME}[2] = "test hash array 2";
$VAR{HASH}{NAME}[3] = "test hash array 3";
$VAR{HASH}{NAME}[4] = "test hash array 4";
Which can't be an issue if you're using
$VAR{HASH}{NAME} = [
undef,
'test hash array 1',
'test hash array 2',
'test hash array 3',
'test hash array 4',
];