Alright I have a function which generates a hash tree that dumper prints out to look like this:
$VAR1 = {
'shaders' => {
'stock_gui.vert' => '',
'stock_font.vert' => '',
'stock_gui.frag' => '',
'stock_font.frag' => ''
},
'textures' => {},
'fonts' => {
'DroidSansMono.ttf' => '',
'small' => {
'DroidSansMono.ttf' => ''
}
}
};
Now I am trying to dfs iterate for example the fonts sub tree:
push (@stack, \%{$myHash->{'fonts'}});
Then in a loop:
my $tmpHash = pop(@stack);
Then a dumper of $tmpHash shows:
$VAR1 = {
'DroidSansMono.ttf' => '',
'small' => {
'DroidSansMono.ttf' => ''
}
};
The problem is trying access the children of the hash reference. I can count the keys and see the children. The dumper output looks okay. However trying to do something like:
foreach my $childKey ( keys $tmpHash ){
my $subChildrenCount = scalar keys(%{$tmpHash->{$childKey}});
}
Yields the error:
Can't use string ("") as a HASH ref while "strict refs" in use
I think this is because $tmpHash is a hash reference. I likely just need to dereference it somewhere. I've tried many things and all yields further issues. Any help appreciated.
If I try:
%{$tmpHash->{'small'}}
Then it works fine.
UPDATE:
- If the string contains a '.' then this error occurs. Hard coding 'small' works. Hard coding 'stock_gui.vert' fails unless I escape the '.'. However the keys do not match if I escape the dot...