Thread m/<irgendwas>/ (14 answers)
Opened by silver345 at 2012-11-21 16:23

silver345
 2012-11-22 07:08
#163514 #163514
User since
2011-06-07
16 Artikel
BenutzerIn
[default_avatar]
Hmm, sicherlich habe ich nur ein - sehr - kurzes Stück Quelltext angegeben. Was mich verwundert ist: Ich füge nur diese eine Zeile hinzu und das Script dreht durch.

Code: (dl )
1
2
3
4
5
6
7
use strict;
use warnings;
...
$fkt_ref->{package} = \&storePackage;
$fkt_ref->{profile} = \&storeProfile;
$fkt_ref->{host} = \&storeHost;
$fkt_ref->{log} = \&storeLog;


steht am Anfang vom Script. Dann Initialisierung des Loggers. Danach wird getopt initialisiert (Funktioniert ohne die RegEx-Zeile gut).

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
my @files;                                           # stores working files
my @contend; # stores files for 2. run
if(-d $site->{PATH}) { # path points to folder
my $fldr = $site->{PATH}; # get all file names in folder
@files = <$fldr/*.xml>;
} else { # path points to a single file
@files = $site->{PATH};
}
foreach my $fl (@files) { # for all files in path
%ret = &getAttribs($site->{FILETYP}, $fl, \$logger);
while ( my($key, $value) = each(%ret) ) { # log all return values
$logger->debug("$key -> $value");
}

if($ret_ref->{ec} eq '251') { # missing field in xml file?
unshift(@wrongs, $fl); # store file name in error array
}

if($ret_ref->{ec} eq '250') { # file not redeable or does not exist
$logger->error("$fl: return code $ret_ref->{ec}");
&WayOut('250', $logger); # go out
}
# select sub depended from FILETYP
my $help = &{ $fkt_ref->{$fltype} }($ret_ref, \$logger);
my $desc ="db error";
if($help < 0) {
$desc = "$fltype $help: exist, skipped"; # do not store file name
} elsif($help > 0) {
$desc = "$fltype $help: inserted";
push @contend, $fl; # store file name for 2. run
} elsif($help == 0) { # something is wrong, log
unshift(@wrongs, $fl);
$desc = "$fltype $help: error, not stored";
}
$logger->debug("$fl: result $desc");
&storeWork($fl, $desc, \$logger);
}
given ($fltype) {
when("package") { $logger->debug("no 2. run"); }
when("profile") { $logger->debug("2. run required!");
my $sp_ret = 0;
foreach my $cont (@contend) {
$sp_ret = &storeContend($cont, $site->{OS}, \$logger);
if($sp_ret == 255) {
unshift(@wrongs, $cont); # store file in error array
}
}
}
when("host") { $logger->debug("no 2. run"); }
when("log") { $logger->debug("no 2. run"); }
}
if(@wrongs > 0) { # print file names with problems
$logger->info("found files with errors. Check logfile.");
foreach my $wrong (@wrongs) {
$logger->debug("wrong: $wrong");
}
} else {
$logger->info("found no files with errors.");
}

&closeDatabase(\@toClose, \$dbh);

&WayOut('0', $logger); # program end


Hauptprogramm. Abhängig vom Eingabeparameter -t wird die entsprechende sub aufgerufen (Zeile 24). In Zeile 10 sammel ich die interessierenden XML-Attribute ein. Bei Übergabe von log wird die Sub storeLog aufgerufen. Die bekommt in $f_vals die Attribute aus Zeile 10 und eine Referenz auf den Logger.

Code: (dl )
1
2
3
4
5
6
7
8
9
sub storeLog {
my $f_vals = shift; # get ref to value hash
my $f_lgr = shift; # get ref to logger handler
my $SubName = (caller(0))[3];

my $os = $f_vals->{os};
$$f_lgr->debug("found XP") if $os =~ /xp professional/;
return 0;
}


Sicherlich ist es in storeLog nicht wirklich notwendig, die Zeile 6 aufzurufen. Aber manchmal versteh ich Referenzen nicht so wirklich (oder zumindest, was sie tun ;o)).

Zusammenfassung:
Solange ich die Zeile 7 in storeLog lösche (auskommentieren reicht nicht. Wieso eigentlich?), läuft das Script ohne Fehlermeldung durch. Also sollte die Klammer-Problematik nicht bestehen. Ansonsten sind die Fehlermeldungen:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
syntax error at ./check line 327, near ") {"
syntax error at ./check line 337, near "}"
syntax error at ./check line 346, near "}"
syntax error at ./check line 420, near ") {"
syntax error at ./check line 423, near ") {"
syntax error at ./check line 424, near ") {"
Global symbol "%attribs" requires explicit package name at ./check line 424.
Global symbol "%attribs" requires explicit package name at ./check line 425.
Global symbol "$f_FileType" requires explicit package name at ./check line 427.
Global symbol "$f_FileType" requires explicit package name at ./check line 428.
Global symbol "$doc" requires explicit package name at ./check line 431.
Global symbol "$f_FileType" requires explicit package name at ./check line 431.
Global symbol "%attribs" requires explicit package name at ./check line 432.
Global symbol "$attribs_ref" requires explicit package name at ./check line 435.
Global symbol "$attribs_ref" requires explicit package name at ./check line 437.
Global symbol "$attribs_ref" requires explicit package name at ./check line 441.
Global symbol "%attribs" requires explicit package name at ./check line 443.
Global symbol "$attribs_ref" requires explicit package name at ./check line 445.
syntax error at ./check line 447, near "}"
./check has too many errors.

Anhänge
text/plain
860 lines
check

View full thread m/<irgendwas>/