Hashes of Hashes in Perl!

Hash is a powerful, flexible data construct in Perl. It is flexible because a single hash can contain within it multiple hashes and arrays. It is powerful because of its key-value nature of storing data. Anyone who plays around with arrays and other complex data structures should give at least a passing look at Perl’s hashes.

At work, I am writing a set of scripts to be run on behalf of a security monitoring client on Linux systems. Fifty percent of the job of the scripts revolves around doing pattern matching and parsing to extract tokens of meaningful data. While most of the task of pattern matching and parsing is doable through only the use of simple hashes, today, I found myself in dire need to use hashes of hashes. Having never used one before, I found myself floundering. I ran a search and found this. It is a neat, clear, and nice introduction to hashes of hashes, along with clear-cut examples. It saved my ass today. :-)

In addition to introducing hashes of hashes, it mentions the Data::Dumper module. I had heard about it, but never before had I seen it used, nor tried it myself. But, god, it is one heck of a nice module to print the contents of any kind of hash, be it simple or complex, with a single call to a function. It makes debugging nightmare a dream. Heh! Enjoy!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s