Thread Inhalt aus Logging zählen (24 answers)
Opened by la_dy82 at 2010-12-14 18:12

dgw
 2010-12-14 18:35
#143568 #143568
User since
2010-08-16
27 Artikel
BenutzerIn

user image
Hi,

Ein Array ist hier nicht das Mittel der Wahl, sondern ein Hash. Oder genauer sogar ein Hash of Hashes (HoH).

Code (perl): (dl )
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
34
35
#!/usr/bin/perl -w

use strict ;
use warnings ;
use Data::Dumper ;

my %data = () ;
while( my $line = <DATA> ) {
  if( my ( $model , $color ) = ( $line =~ m/^\d{4}\.\d{2}\.\d{2}\s+\d{2}:\d{2}:\d{2}\s+(\S+)\s+(\S+)/ ) ) {
    if( ! exists $data{$model} ) {
      $data{$model} = {} ;
    }
    if( ! exists $data{$model}->{$color} ) {
      $data{$model}->{$color} = 0 ;
    }
    $data{$model}->{$color}++ ;
  }
}

$Data::Dumper::Indent = 1 ;
printf "Data:\n%s\n" , Dumper( \%data ) ;

exit ;

__DATA__
2010.09.15      06:01:55        TZ_19_C blau
2010.09.15      06:02:15        FR_90_X schwarz
2010.09.15      06:05:15        TZ_19_C gelb
2010.09.15      06:05:35        TZ_19_B rot
2010.09.15      06:07:22        TZ_19_C blau
2010.09.15      06:07:42        FR_90_X rosa
2010.09.15      06:09:29        TZ_19_B rot
2010.09.15      06:09:49        FR_90_X rosa
2010.09.15      06:11:36        TZ_19_C gelb
2010.09.15      06:11:55        TZ_19_C blau


Ich hoffe das hilft weiter.
Daniel

View full thread Inhalt aus Logging zählen