Leser: 1
6 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
sub make_stat {
my ($tmpdir, $logfile) = @_;
my @words;
open(LOG, "<$tmpdir/$logfile") or die("Can't open logfile. $!");
for my $line (<LOG>) {
#print $line;
my @parts = split(/ /,$line);
my $time = shift(@parts);
my $user = shift(@parts);
for (my $i=0;$i<scalar(@parts);$i++) {
next if ( (length($parts[$i]) < 3) || ($parts[$i] =~ m/(;|:|\(|\)|\/|<|>|)/) ); #smilies und kurze worte aussortieren
push(@words, [$parts[$i], 1]) if (scalar(@words) < 1);
my $found = 0;
my $j = 0;
for (@words) {
if ($words[$j][0] eq $parts[$i]) {
$words[$j][1]++; #wort hochzaehlen
$found = 1;
last;
}
$j++;
}
push(@words, [$parts[$i], 1]) unless $found;
}
}
close LOG or die("Can't close logfile. $!");
for my $i (0..scalar(@words)) {
print "$words[$i][0], $words[$i][1]\n";
}
} #sub make_stat
1
2
3
4
5
(00:10) <Henda> =(
(00:10) <pHyL> seufzt :[
(00:12) <styx> mhmh
(00:12) <styx> jetzt passieren kommische dinge
(00:13) <Henda> welche denn?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use strict;
use warnings;
use Data::Dumper;
my @vfile = (
"(00:10) <Henda> =(\n",
"(00:10) <pHyL> welche denn ? seufzt :[\n",
"(00:12) <styx> mhmh\n",
"(00:12) <styx> jetzt passieren mhmh kommische dinge\n",
"(00:13) <Henda> welche denn?\n",
);
my %stats;
while (defined (my $line = shift @vfile)) {
my ($time, $user, @words) = split /\s+/, $line;
foreach my $word (@words) {
next if $word =~ /[;:=][\W]+/ || length($word) < 3;
$word =~ s/(\w+)\W+$/$1/; # wegen "denn" und "denn?"
$stats{$word}++;
}
}
print Dumper(\%stats);
1
2
my @sorted_words = reverse sort { $stats{$a} <=> $stats{$b} } keys %stats;
print "$_: $stats{$_}\n" for @sorted_words;
6 Einträge, 1 Seite |