CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [FishMonger] Stuck on how to iterate a list in a file against a logfile.: Edit Log


Jun 19, 2012, 8:53 AM

Views: 10607
Re: [FishMonger] Stuck on how to iterate a list in a file against a logfile.

Thanks Fishmonger,

Still not getting any hits. Here is some sample data:

1323666001.661 172 TCP_MISS/200 3625 GET - DIRECT/ text/html
1323666001.985 238 TCP_MISS/304 237 GET - DIRECT/ -
1323666002.310 165 TCP_CLIENT_REFRESH_MISS/304 237 GET - DIRECT/ -
1323666002.683 158 TCP_CLIENT_REFRESH_MISS/304 237 GET - DIRECT/ -
1323666002.999 164 TCP_CLIENT_REFRESH_MISS/304 235 GET - DIRECT/ -
1323666003.308 165 TCP_MISS/304 237 GET - DIRECT/ -
1323666003.656 161 TCP_MISS/301 404 GET - DIRECT/ -
1323666003.991 12 TCP_MISS/200 1168 GET - DIRECT/ application/rss+xml
1323666006.596 4 TCP_HIT/200 213 HEAD - NONE/- text/html

and ip.txt looks like:


Here is what I think occurring with your code.

1. Your loading the ip addresses into a hash called "ip"
2. looping through the list to strip of any new lines.

The next while loop allows us to to parse the input log file.

I am unsure why you are splitting here:

my $ip = (split(/\s/, $_))[2];

The remainder of the code is checking if the key value is in the data to be parsed.

However, when I run

./ sample.txt

I get no results. However clearly the IP addresses in the ip.txt file are present in the log file.

Thanks again for all the help on this.

(This post was edited by asandybox on Jun 19, 2012, 8:55 AM)

Edit Log:
Post edited by asandybox (Novice) on Jun 19, 2012, 8:55 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives