Hash Idioms
Get to know about hash idioms and locking hashes in Perl.
Finding unique values with undef
Each key exists only once in a hash, so assigning multiple values to the same key stores only the most recent value. This behavior has advantages! For example, we can find unique elements of a list:
Using undef with a hash slice sets the hash values to undef. This idiom is the cheapest way to perform set operations with a hash.
Counting occurrences
Hashes are useful for counting elements, such as IP addresses in a log file:
The initial value of a hash value is undef. The post-increment operator ++ treats that as zero. This in-place modification ...