Hello folks,
I'm wondering if any of you could help me with a code problem? I'm relatively new to Perl, coming to it from AppleScript, and I've written a Perl script that parses my server access_log and creates a hash of hashes that looks essentially like this:
192.168.1.1 = $user_agent = "...GoogleBot..." $user_type = "robot" 192.168.1.3 = $user_agent = "...Linux...Firefox..." $user_type = "human" 192.168.1.4 = $user_agent = "...Yahoo! Slurp..." $user_type = "robot" 192.168.1.5 = $user_agent = "...Windows...MSIE..." $user_type = "human" etc...
So, in the first hash, the ip address is the key and the value is the second, nested hash.
I want to traverse that hash of hashes to extract the user agent of each IP whose user type is "robot" like this:
LIST OF ROBOTS VISITING SITE: 192.168.1.1 "...GoogleBot..." 192.168.1.4 "...Yahoo! Slurp..." etc...
I've been struggling with various versions of a foreach loop but can't seem to get it to work. Is it possible to traverse a hash of hashes and extract data based on a value from a key/value pair that is nested in another hash?
I could just create two hashes, one for humans and one for robots, but one hash that contains all the information seemed to be a more elegant solution...
Any help would be greatly appreciated.
Thanks,
James