creating a hash
Posted on 2000-03-25
I have a file containing IP addresses. I want to read a file, and make a hash with IPs being the keys and the number of times that IP appears in the file as the value. So a file like this:
would create a hash like this:
%ips = (
0.0.0.0 => 1,
18.104.22.168 => 2,
22.214.171.124 => 3,
What I really need this for is counting IP accesses in a log file. I'll parse the log file, and:
1. if the IP is not already in the hash, add a key/value pair of <IP>=>"1".
2. if the IP is already in the hash, increment the value.
(how is this done?)