in reply to recursively building a hash of arrays of scalars
Hello aral,
I do not even know whether the "problematic line" is able to create a valid reference, because element 'a' does not exist at the time.
It is able to do this, as you can see by dumping the contents of %testHash immediately afterwards:
#! perl use strict; use warnings; use Data::Dump; my %testHash; # initialize hash my $hashRef = \%testHash; # get a reference to that # get a reference to an element 'a' inside the hash (that does not yet + exist) my $destref = \${$hashRef->{'a'}}; # <- problematic line dd \%testHash;
Output:
2:28 >perl 1389_SoPW.pl { a => \undef } 2:28 >
This occurs because of autovivification, an important feature of Perl. See the tutorial “Autovivification: What is it and why do I care?” by Uri Guttman.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|