in reply to Trying to understand hashes (in general)

Just because a hash stores key/value pairs doesn't mean that you need to put anything useful in the value.

C++ comes with std::unordered_set and std::unordered_map. The first one is designed for just a set of keys. The second is a set of keys that map to values. The second one is more like Perl's hashes. But the fact that the two different containers exist is mostly a matter of memory efficiency and semantic purity.

Now back to Perl: Your hashes won't be growing too big, so memory efficiency probably isn't an issue, and we don't need to be too particular about semantic purity. Hashes often may be used where you might think in terms of sets.

my %heros; @heros{ qw( thetick wonderwoman batman superman spiderman ) } = (); print "Yes!\n" if exists $heros{thetick};

In the code above we're creating a hash called %heros that contains elements named for various superheros. But we don't explicitly assign a value to each of the elements. Their value is undefined, and it really doesn't matter because we never use it. Later we test to see if 'thetick' is among our set of superheros.


Dave