|
|
|
|
|
by disgusting_guy
3153 days ago
|
|
Agreed -- there are far too many pitfalls that you only really learn through debugging strange behaviour. Autovivication is a perfect example of this: perl -wE 'my @test; say $test[5]{yes}[0]{ok}++; say scalar @test; say ref $test[5]; say $test[5]{yes}[0]{ok}'
outputs: 0
6
HASH
1
with not a single warning |
|
I hate C#'s way of assigning a value to a dictionary, without autovivification:
You also have to use ContainsKey before you try to use [] to retrieve a value, because [] throws an exception if the key doesn't exist in the dictionary. Perl's autovivification, which assumes you know what you're doing and expect the key to be there when you ask for the value rather than explicity check for the key, makes much more sense and is a lot easier to work with.