Leser: 3
![]() |
|< 1 2 >| | ![]() |
20 Einträge, 2 Seiten |
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
#!/opt/perl5.8.6/bin/perl -w
use Time::Local;
my $dir = "/pfad/";
my $oldname = 0;
my %dif_hash;
opendir(DIR, "$dir");
my @files = readdir(DIR);
closedir(DIR);
print "Inhalt von $dir:\n";
foreach (@files) {
#auszulesendedatei.20070117.001124.log
m/(.*)\.(\d{4})(\d{2})(\d{2})\.(\d{2})(\d{2})(\d{2})\.log/;
if ( $1 ne $oldname )
{
%div_hash = ($1 => {begin => {
name => $1,
year => $2,
month => $3,
day => $4,
hour => $5,
minute => $6,
second => $7,
}
}
);
}
else
{
%div_hash = ($1 => {end => {
name => $1,
year => $2,
month => $3,
day => $4,
hour => $5,
minute => $6,
second => $7,
}
}
);
}
$oldname = $1;
}
foreach ($div_hash)
{
print "$_ \n";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Hash aus Hashes:
my %h = (
'erster' => { 'schl1' => 'wert', 'schl2' => 'wert', 'schl3' => 'wert', },
'zweiter' => { 'schl1' => 'wert', 'schl2' => 'wert', 'schl3' => 'wert', },
);
# Zugriff auf die Hashes im Hash:
print Dumper $hash{erster};
print Dumper $hash{erster}->{schl1}
# Eine Hashreferenz:
my $href = {
'abc' => 'def',
}; # man beachte den Unterschied, dass geschweifte Klammern benutzt werden anstatt runde
print $href->{abc};
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
#!/opt/perl5.8.6/bin/perl -w
use Time::Local;
my $dir = "/pfad/";
my $oldname = 0;
my %dif_hash;
opendir(DIR, "$dir");
my @files = readdir(DIR);
closedir(DIR);
print "Inhalt von $dir:\n";
foreach my $file (@files) {
#auszulesendedatei.20070117.001124.log
my @info = $file =~ m/(.*)\.(\d{4})(\d{2})(\d{2})\.(\d{2})(\d{2})(\d{2})\.log/;
if ( $info[0] ne $oldname )
{
my %subhash = ();
@subhash{ qw/name year month day hour minute second/ } = @info;
$div_hash{ $info[0] } = {
begin => { %subhash }
};
}
else
{
my %subhash = ();
@subhash{ qw/name year month day hour minute second/ } = @info;
$div_hash{ $info[0] } = {
end=> { %subhash }
};
}
$oldname = $1;
}
print Dumper(\%div_hash);
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 }
my @files = readdir(DIR);
1
2
3
4
5
my @files = grep{
$_ !~ /\.\.?$/ # filter . und ..
and
-f $dir.'/'.$_ # überprüfe, ob es eine datei ist
}readdir(DIR);
![]() |
|< 1 2 >| | ![]() |
20 Einträge, 2 Seiten |