Re: traversing (and accessing values in) a hash of hashes

2004-12-12 Thread James marks
Lawrence (and all), I haven't gotten a chance to dig into the examples and work on the problem yet but I wanted to say thanks for the help. For example: Is using the IP address as the key really a good idea? Might an IP address be assigned to two different users -- or might a person use two diffe

Re: traversing (and accessing values in) a hash of hashes

2004-12-11 Thread James marks
Jonathan, That had occurred to me part way through writing the script. I'm learning Linux, Apache, MySQL and Perl/PHP all at the same time so sometimes I get halfway through a project in one area then learn something new in another area that causes me to have to back the first project and do a

Re: traversing (and accessing values in) a hash of hashes

2004-12-11 Thread John W. Krahn
James marks wrote: Hello folks, Hello, 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

Re: traversing (and accessing values in) a hash of hashes

2004-12-11 Thread Lawrence Statton
> In the script, there are two variables produced from a regexp match > against the current line in the access_log: > > $new_ip > $user_agent > > and one that is determined by a subroutine that looks for clues that > the user_agent is a robot: > > $user_type > > This is the subroutine that bu

Re: traversing (and accessing values in) a hash of hashes

2004-12-11 Thread Jonathan Paton
Dear James, A way to work with that datastructure would be: my %hash = ...; my @robots; for my $ip (keys %hash) { my $type = $hash{$ip}{type}; push @robots, [ $ip, $hash{$ip}{agent} ] if $type eq "robot"; } I suggest you use an array of hashes, in the form: my @array = ( { ip => .

Re: traversing (and accessing values in) a hash of hashes

2004-12-11 Thread James marks
In the script, there are two variables produced from a regexp match against the current line in the access_log: $new_ip $user_agent and one that is determined by a subroutine that looks for clues that the user_agent is a robot: $user_type This is the subroutine that builds the hash of hashes. I

Re: traversing (and accessing values in) a hash of hashes

2004-12-11 Thread Lawrence Statton
> 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 = >

Re: traversing (and accessing values in) a hash of hashes

2004-12-11 Thread Lawrence Statton
> > I want to traverse that hash of hashes to extract the user agent of > > each IP whose user type is "robot" like this: > D'OH! I just re-read the problem ... amend to read print "$key \"$log{$key}{user_agent}\"\n" if $log{$key}{user_type} eq 'robot'; -- -- -- -- -- -- -- --

Re: traversing (and accessing values in) a hash of hashes

2004-12-11 Thread Oliver Schnarchendorf
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/b

traversing (and accessing values in) a hash of hashes

2004-12-11 Thread James marks
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 =