On Sat, 11 Dec 2004 15:58:48 -0800, James marks wrote: > 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... #!/usr/local/bin/perl
use diagnostics; use warnings; use strict; my %ip_addresses = ( '192.168.2.1' => { 'user_agent' => 'Google bot', 'user_type' => 'robot', }, '192.168.2.2' => { 'user_agent' => 'Netscape 7.x', 'user_type' => 'human', }, '192.168.2.3' => { 'user_agent' => 'Mac IE 5.3', 'user_type' => 'human', }, '192.168.2.5' => { 'user_agent' => 'Yahoo Slurp', 'user_type' => 'robot', }, ); foreach my $ip_address (keys %ip_addresses) { if ($ip_addresses{$ip_address}{'user_type'} eq 'robot') { print "$ip_address: $ip_addresses{$ip_address}{'user_agent'}\n"; } } You might want to take a look at 'perldoc perlref' to understand nested data structures. /oliver/ -- "If you believe everything you read, you better not read." -Japanese Proverb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>