Thread Hash von Hashes einstiegsprobleme (19 answers)
Opened by v0id at 2007-03-12 18:01

v0id
 2007-03-13 10:16
#74958 #74958
User since
2005-07-06
33 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
38
39
40
41
42
43
44
     1  #!/opt/perl5.8.6/bin/perl -w
2
3 #use strict;
4 use Time::Local;
5 use Data::Dumper;
6
7 my $dir = "/pfad/";
8 my $oldname = 0;
9
10 my %dif_hash = ();
11
12 opendir(DIR, "$dir");
13 my @files = readdir(DIR);
14 closedir(DIR);
15
16 print "Inhalt von $dir:\n";
17
18 foreach my $file (@files) {
19 #dateiname.20070117.001124.log
20 my @info = ();
21 @info = $file =~ m/(.*)\.(\d{4})(\d{2})(\d{2})\.(\d{2})(\d{2})(\d{2})\.log/;
22
23 if ( $info[0] ne $oldname )
24 {
25 my %subhash = ();
26 @subhash{ qw/name year month day hour minute second/ } = @info;
27
28 $div_hash{ $info[0] } = {
29 begin => { %subhash }
30 };
31 }
32 else
33 {
34 my %subhash = ();
35 @subhash{ qw/name year month day hour minute second/ } = @info;
36
37 $div_hash{ $info[0] } = {
38 end => { %subhash }
39 };
40 }
41
42 $oldname = $1;
43
44 }


ich habe es zuerst mit diesem code versucht, jedoch bekomme ich (ohne use strict) die meldungen:
Use of uninitialized value at dir_4.pl line 23.
Use of uninitialized value at dir_4.pl line 28.
Use of uninitialized value at dir_4.pl line 28.
Use of uninitialized value at dir_4.pl line 23.
Use of uninitialized value at dir_4.pl line 23.
Use of uninitialized value at dir_4.pl line 37.
Use of uninitialized value at dir_4.pl line 23.
Use of uninitialized value at dir_4.pl line 23.
Use of uninitialized value at dir_4.pl line 28.
Use of uninitialized value at dir_4.pl line 23.
Use of uninitialized value at dir_4.pl line 28.

ich verstehe nur nicht wieso die variablen nicht initialisiert sein sollen. dahinter steht dann noch ein teil vom code der sich wiederholt, und zwar die abfrage mit den richtigen inhalten, bis auf den zweiten welcher undef ist.

mit strict bekomme ich lediglich:
Global symbol "%div_hash" requires explicit package name at dir_4.pl line 28.
Execution of dir_4.pl aborted due to compilation errors.

vielleicht könntet ihr mir nochmal aus der patsche helfen.
das script soll ansich alle dateien aus dem ordner durchgehen, viele haben den gleichen namen bis auf die zahlen am ende. es soll quasi immer die erste und die letzte datei die gleich heißt gespeichert werden. anschliessend soll die nächste datei mit anfang und ende gespeichert werden usw..

View full thread Hash von Hashes einstiegsprobleme