Dru has asked for the wisdom of the Perl Monks concerning the following question:
# Script to go through file and count the number # of times an ip appears; use strict; use warnings; my $file = 'd:\temp\file.csv'; my %hash; open (FILE, $file) or die "Can't open $file: $!\n"; while (<FILE>){ my($src, $dst, $rule1) = (split /,/)[1]; $hash{$src} = $src; next if $src =~ /$hash{$src}/; } my $count; for (keys %hash){ while (<FILE>){ if ($_ =~ /$hash{$_}/){ $count++; } $hash{$_}{times} = $count; } } for my $ip (keys %hash){ print "$ip was seen $hash{$ip} times\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting the Number of Times and IP Appears
by atcroft (Abbot) on Feb 19, 2004 at 22:39 UTC | |
|
Re: Counting the Number of Times and IP Appears
by borisz (Canon) on Feb 19, 2004 at 22:33 UTC | |
|
Re: Counting the Number of Times and IP Appears
by borisz (Canon) on Feb 19, 2004 at 22:46 UTC | |
|
Re: Counting the Number of Times and IP Appears
by QM (Parson) on Feb 19, 2004 at 22:58 UTC | |
by Dru (Hermit) on Feb 20, 2004 at 03:41 UTC |