I have decided to give Perl a try and I have stumbled across a language structure that seems to be valid, but I just can't believe it is. As I guess there is some rationale behind this I decided to ask a question.
Take a following Perl code:
%data = ('John Paul' => ('Age' => 45), 'Lisa' => 30);
print "\$data{'John Paul'} = $data{'John Paul'}{'Age'}\n";
print "\$data{'Lisa'} = $data{'Lisa'}\n";
My intention was to check how hash of hashes works. The above code prints:
$data{'John Paul'} =
$data{'Lisa'} =
To make it a valid hash of hashes one needs:
%data = ('John Paul' => {'Age' => 45}, 'Lisa' => 30);
and the result would be:
$data{'John Paul'} = 45
$data{'Lisa'} = 30
Does anyone know:
- Why there is non uniformity and the internal hash needs
{}
instead of()
? - Why do I get no error or warning that something is wrong when there is
()
instead of{}
for the internal hash? It is very easy to do such kind of mistakes. What is more,('Age' => 45)
breaks not only the value for'John Paul'
but also for'Lisa'
. I just can't imagine searching for such kind of "bugs" in project with thousands lines of code.