Thread fehler beim ausgeben eines hashes (7 answers)
Opened by mr-sansibar at 2006-05-22 18:17

renee
 2006-05-22 20:49
#7741 #7741
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Du kannst als Values eines Hashs kein Array nehmen, sondern nur Skalare (siehe perlreftut).

Ich hab' mal was auf die Schnelle gemacht:
Code: (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;

my $output;

GetOptions('-output=s' => \$output);
my $logfile = $ARGV[0];
print_usage() unless($logfile);

my @errors = qw(
FrontEndException
SocketException
ArrayIndexOutOfBoundsException
NullPointerException
LockedPinException
AuthenticationException
BusinessServiceException
IllegalStateException
NumberFormatException
Exception
NoSuchElementException
RemoteException
SQLException
IOException
FileNotFoundException
);

my $string = '';
my ($key,$date,$time);

open(my $fh,'<',$logfile) or die $!;
while(my $line = <$fh>){

if($line =~ /Severity: Error/){
$hash{$key} = $string;
$key = '';
$date = '';
$time = '';
}
else{
$string .= $line;
}

if($line = /Date:/){
$date = $line;
}
elsif($line =~ /Zeit:/){
$time = $line;
}

if($date && $time){
$key = "serapis1".substr($Datum, 12, 4).substr($Datum, 9, 2).substr($Datum, 6, 2).$Zeit
}

for my $error(@errors){
if($line =~ /$error/){
$error_hash{$error}++;
}
}
}
close $fh;

my $wh;
if($output){
open(my $wh,'>>',$output) or die $!;
}
else{
$wh = STDOUT;
}

for my $key(sort(keys(%hash))){
print $wh $key,": ",$hash{$key},"\n";
}
for my $error(@errors){
print $wh $error,": ",$error_hash{$error},"\n";
}
close $wh;

sub print_usage{
print qq~Usage: $0 [--output FILE] logfile\n~;
exit;
}
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread fehler beim ausgeben eines hashes