Let's say you do the following. In this example, the name of the hash is %hash and the hash contains a key named employees_key. employees_key is an empty array, as indicated by the [ ] characters.
my %hash = ( 'employees_key' => [] );
You could use Dumper to display the structure.
use Data::Dumper;
print Dumper \%hash;
employees_key is empty.
$VAR1 = {
'employees_key' => []
};
Multiple arrays
Let's say you do this.
my %hash = ( 'employees_key' => [], 'departments_key' => [] );
Now the hash contains two empty arrays.
$VAR1 = {
'employees_key' => [],
'departments_key' => []
};
Multidimensional arrays
Let's say you do this.
push @{$hash{employees_key}}, { 'departments_key' => [] };
Now the hash contains two arrays, the employees_key array and the departments_key array, where the departments_key array is a child of the employees_key array. The departments_key array is empty. However, the employees_key array is not empty, since the employees_key array contains departments_key.
$VAR1 = {
'employees_key' => [
{
'departments_key' => []
}
]
};
Let's say you do this.
push @{$hash{employees_key}}, { 'main' => { 'departments_key' => [] } };
Now, below employees_key array is the main_key hash, and below the main"_key hash is the departments_key array.
$VAR1 = {
'employees_key' => [
{
'main_key' => {
'departments_key' => []
}
}
]
};
Don't do this
Let's say you do this.
push @{$hash{employees_key}}, "departments_key";
Now the employees_key array contains a value. The value is departments_key. This is outside of the scope of creating an empty array. Instead, this is how you append values to an array.
$VAR1 = {
'employees_key' => [
'departments_key'
]
};