in reply to how to set a value for a hash reference

A hash consists of "values" indexed by "strings." Those "values" can be discrete numbers, or references to anything-at-all.

If the value that you are reading isn't there, you get "undef."

If you are setting a value, as with "++", or referring to a not-yet existing hash entry on a more complicated assignment statement, Perl automagically creates ("auto-vivifies") the necessary entries on-the-fly, giving them (in the case of "++") an initial value of zero. In other words, "if the success of this statement relies upon the value being there, such that the programmer would have to waste time and resources checking-first but for no other purpose, just cause it to be there ... thus saving valuable computer-time in a convenient action that is obviously correct."

  • Comment on Re: how to set a value for a hash reference