Schrift
[thread]733[/thread]

fehler beim ausgeben eines hashes



<< >> 8 Einträge, 1 Seite
mr-sansibar
 2006-05-22 18:17
#7734 #7734
User since
2006-04-13
90 Artikel
BenutzerIn
[default_avatar]
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
while ( <lesen2> ) {

push @lines, $_;

my $Datum = $_ if m/Date: /;
my $Zeit = $_ if m/Zeit: /;
push @lines, $_;


$Zeit =~ s/\D//g;

#generierung von einem key
my $dt = "serapis1".substr($Datum, 12, 4).substr($Datum, 9, 2).substr($Datum, 6, 2).$Zeit;
     
if ( /^\s*$/ ) {
        if ($errorFound eq 1) {
        my %hashref = ($dt => @lines);
       
        @lines = '';  
    $errorFound = 0;
    }
   }
   
   $errorFound = 1 if /Severity: Error/;
 
  m/NullPointerException/;
   $LockedPinException++ if m/LockedPinException/;
   $AuthenticationException++ if m/AuthenticationException/;
       $Exception++ if m/\.Exception/;
   $NoSuchElementException++ if m/NoSuchElementException/;
$RemoteException++ if m/RemoteException/;    
   
}

while (($dt, @lines) = each %ENV) {
print OUT "$dt => @lines\n";
}


bekomme hier und bei der while -schleife ein fehler meldung: Global symbol "$dt" requires explicit package name at trxLogParser_2006-05-19.pl line 173.

edit pq: quote-tags um den code herum in code-tags verwandelt.\n\n

<!--EDIT|pq|1148311754-->
Froschpopo
 2006-05-22 18:21
#7735 #7735
User since
2003-08-15
2653 Artikel
BenutzerIn
[default_avatar]
edit.\n\n

<!--EDIT|Froschpopo|1148307685-->
mr-sansibar
 2006-05-22 18:25
#7736 #7736
User since
2006-04-13
90 Artikel
BenutzerIn
[default_avatar]
was meinst du mit edit ?
Strat
 2006-05-22 18:59
#7737 #7737
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
das $dt in der unteren while-schleife ist nicht deklariert;
Code: (dl )
1
2
3
while( (my $dt, @lines) = each %ENV )  {
...
} # while

ich verstehe den Code nicht so recht.
Code: (dl )
1
2
3
4
5
6
7
8
solange du eine zeile aus dem FH lesen lesen kannst, wird die zeile $_ zugewiesen
fuege die zeile (inkl. zeilenumbruch) ans ende von @lines an
wenn in der Zeile Date: steht, speichere sie in $Datum
wenn in der Zeile Zeit: steht, speichere sie in $Zeit
fuege die zeile (inkl. zeilenumbruch) nochmal ans ende von @lines an
loesche aus $Zeit alle Zeichen, die keine Ziffern sind, egal, ob $Zeit befuellt ist oder nicht
baue einen Key zusammen => $dt
...

%hashref ist ein hash, keine $hashReferenz

Code: (dl )
if ($errorFound eq 1) 

eq vergleicht zwei zeichenketten
== vergleicht zwei zahlen
also:
Code: (dl )
if ($errorFound == 1) 

(oder, wenn du nur mit 0 und 1 arbeitest, einfach:
Code: (dl )
if ($errorFound) 

Code: (dl )
m/NullPointerException/;

hat keine auswirkung\n\n

<!--EDIT|Strat|1148310019-->
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
Strat
 2006-05-22 19:01
#7738 #7738
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code: (dl )
1
2
3
while( (my $dt, @lines) = each %ENV )  {
...
} # while

hier lautet die syntax normalerweise
Code: (dl )
1
2
3
while( my($key, $value) = each %ENV )  {
...
} # while

also kein array @lines
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
mr-sansibar
 2006-05-22 20:12
#7739 #7739
User since
2006-04-13
90 Artikel
BenutzerIn
[default_avatar]
vielen dank.
bin noch anfänger.

kannst du mir noch ein tipp geben wie ich ein hash ausgeben kann, am besten ich gebe dir den ganzen code, dass müsste für Dich kein problem sein :blush:
habe zuvor mit c++ prgrammiert und mir fällt es einwenig schwer mit perl. kannst du mir eine IDE empfehlen, wo ich zumindestens debigging machen.

vielen dank !!!

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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use strict;
use warnings;
use Getopt::Long;

# the cmd-line-arg --output
my $output = 0;
GetOptions(
 'output=s' => \$output,
);


#my $write_file = "/iwmnt/default/main/test-dekabank-01/WORKAREA/dev-deka/trxlogfile.txt";
my $write_file = "c:/trxlogfile.txt";


# print usage, if no logFile is
# given as cmd-line-arg

die "usage: TrxLogParser.pl [--output FILE] logFile\n"
   unless $ARGV[0];


open (lesen1, "<$ARGV[0]")  || die "Kann datei1 Nicht lesen: $!";
open (lesen2, "<$ARGV[1]")  || die "Kann datei2 Nicht lesen: $!";
open( OUT, ">>$write_file" ) || die "Kann die Datei nicht erzeugen: $!";


# the lines and the errorFound-flag
my @lines;
my %hashref;
my $errorFound = 0;

my $FrontEndException = 0;
my $SocketException = 0;
my $ArrayIndexOutOfBoundsException = 0;
my $NullPointerException = 0;
my $LockedPinException = 0;
my $AuthenticationException = 0;
my $BusinessServiceException = 0;
my $IllegalStateException = 0;
my $NumberFormatException = 0;
my $Exception = 0;
my $NoSuchElementException = 0;
my $RemoteException = 0;
my $SQLException = 0;
my $IOException = 0;
my $FileNotFoundException = 0;


while ( <lesen1> ) {

push @lines, $_;

my $Datum = $_ if m/Date: /;
my $Zeit = $_ if m/Zeit: /;
push @lines, $_;


$Zeit =~ s/\D//g;
my $dt = "kemuer1".substr($Datum, 12, 4).substr($Datum, 9, 2).substr($Datum, 6, 2).$Zeit;

#hier erfolgt das zusammensetzten der string im richtig schlssel string
   if ( /^\s*$/ ) {
        if ($errorFound eq 1) {
        %hashref = ($dt => @lines);

        @lines = '';
    $errorFound = 0;
    }
   }

   $errorFound = 1 if /Severity: Error/;

  $FrontEndException++ if m/FrontEndException/;
   $SocketException++ if m/socketException/;
   $ArrayIndexOutOfBoundsException++ if m/ArrayIndexOutOfBoundsException/;
   $NullPointerException++ if m/NullPointerException/;
   $LockedPinException++ if m/LockedPinException/;
   $AuthenticationException++ if m/AuthenticationException/;
   $BusinessServiceException++ if m/\.BusinessServiceException/;
   $IllegalStateException++ if m/IllegalStateException/;
   $NumberFormatException++ if m/NumberFormatException/;
   $Exception++ if m/\.Exception/;
   $NoSuchElementException++ if m/NoSuchElementException/;
$RemoteException++ if m/RemoteException/;
$SQLException++ if m/SQLException/;
$IOException++ if m/IOException/;
$FileNotFoundException++ if m/FileNotFoundException/;

foreach $dt (keys  %hashref) {
print OUT "$dt => @lines\n";


}
while ( <lesen2> ) {

push @lines, $_;

my $Datum = $_ if m/Date: /;
my $Zeit = $_ if m/Zeit: /;
push @lines, $_;


$Zeit =~ s/\D//g;

#generierung von einem key
my $dt = "serapis1".substr($Datum, 12, 4).substr($Datum, 9, 2).substr($Datum, 6, 2).$Zeit;



   if ( /^\s*$/ ) {
        if ($errorFound eq 1) {
        my %hashref = ($dt => @lines);

        @lines = '';
    $errorFound = 0;
    }
   }

   $errorFound = 1 if /Severity: Error/;

  $FrontEndException++ if m/FrontEndException/;
   $SocketException++ if m/socketException/;
   $ArrayIndexOutOfBoundsException++ if m/ArrayIndexOutOfBoundsException/;
   $NullPointerException++ if m/NullPointerException/;
   $LockedPinException++ if m/LockedPinException/;
   $AuthenticationException++ if m/AuthenticationException/;
   $BusinessServiceException++ if m/\.BusinessServiceException/;
   $IllegalStateException++ if m/IllegalStateException/;
   $NumberFormatException++ if m/NumberFormatException/;
   $Exception++ if m/\.Exception/;
   $NoSuchElementException++ if m/NoSuchElementException/;
$RemoteException++ if m/RemoteException/;
$SQLException++ if m/SQLException/;
$IOException++ if m/IOException/;
$FileNotFoundException++ if m/FileNotFoundException/;

foreach $dt (keys  %hashref) {
print OUT "$dt => @lines\n";

}
#end for schleife
#}

}

print OUT "FrontEndException:  $FrontEndException\n
SocketException: $SocketException\n
ArrayIndexOutOfBoundsException: $ArrayIndexOutOfBoundsException\n
NullPointerException: $NullPointerException\n
LockedPinException: $LockedPinException\n
AuthenticationException: $AuthenticationException\n
BusinessServiceException: $BusinessServiceException\n
IllegalStateException: $IllegalStateException\n
NumberFormatException: $NumberFormatException\n
Exception: $Exception\n
NoSuchElementException: $NoSuchElementException\n
RemoteException: $RemoteException\n
SQLException: $SQLException\n
IOException: $IOException\n
FileNotFoundException: $FileNotFoundException\n";

# close the handle
close OUT;
Ronnie
 2006-05-22 20:20
#7740 #7740
User since
2003-08-14
2022 Artikel
BenutzerIn
[default_avatar]
[quote=mr-sansibar,22.05.2006, 18:12]kannst du mir eine IDE empfehlen, wo ich zumindestens debigging machen.[/quote]
CPAN:Devel::ebug::http ist als Debugger ganz nett. Als IDE kann man u.a. den Editor von Lichtkind empfehlen http://proton-ce.sourceforge.net/site/en/home_news.shtml
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/
<< >> 8 Einträge, 1 Seite



View all threads created 2006-05-22 18:17.