Thread Empfehlung Datenbank als Datei (37 answers)
Opened by bianca at 2019-10-20 19:55

rosti
 2019-10-21 19:38
#190777 #190777
User since
2011-03-19
2725 articles
BenutzerIn
[Homepage]
user image
Code (perl): (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
use FastEAV;
my $f = FastEAV->new( file => "personen.eav", lock => 1) or die $^E;
# Personen in Array
my $per = [
    {name => 'Hinz', vname=> 'Horst'},
    {name => 'Kunz', vname=> 'Erwin'},
    {name => 'Huber', vname=> 'Karl-Heinz'},
    {name => 'Haar', vname=> 'Franz'}
];
foreach my $e ( 0 .. scalar @$per - 1 ){
    # [index] + 1
    $f->checkin(1+$e, %{$per->[$e]});
}
$f->write;
$f = undef;

# Personen wiedr auslesen
my $dal = FastEAV->new( file => "personen.eav") or die $^E;
foreach my $ent( $dal->count){
    say Dumper $dal->checkout($ent);
}


# nun eine Hash Of Hashes
my $eav = {
    1 => {name => 'Hinz', vname=> 'Horst', plz => 12345},
    2 => {name => 'Kunz', vname=> 'Erwin', plz => 55555},
    a => {name => 'Huber', vname=> 'Karl-Heinz', plz => 11011},
    b => {name => 'Haar', vname=> 'Franz', ort => 'Erfurt', plz => 99081}
};

foreach my $ent ( keys %$eav ){
    $dal->checkin($ent, %{$eav->{$ent}} );
}
$dal->write;
undef $dal;

# Kontrolle on alles gespeichert wurde
my $fast = FastEAV->new( file => "personen.eav") or die $^E;
foreach my $ent( $fast->count){
    say Dumper $fast->checkout($ent);
}

# Ausgabe
$VAR1 = {
          'name' => 'Haar',
          'vname' => 'Franz'
        };

$VAR1 = {
          'name' => 'Hinz',
          'vname' => 'Horst'
        };

$VAR1 = {
          'name' => 'Huber',
          'plz' => '11011',
          'vname' => 'Karl-Heinz'
        };

$VAR1 = {
          'name' => 'Huber',
          'vname' => 'Karl-Heinz'
        };

$VAR1 = {
          'name' => 'Haar',
          'ort' => 'Erfurt',
          'plz' => '99081',
          'vname' => 'Franz'
        };

$VAR1 = {
          'name' => 'Kunz',
          'vname' => 'Erwin'
        };

$VAR1 = {
          'name' => 'Hinz',
          'plz' => '12345',
          'vname' => 'Horst'
        };

$VAR1 = {
          'name' => 'Haar',
          'vname' => 'Franz'
        };

$VAR1 = {
          'name' => 'Huber',
          'plz' => '11011',
          'vname' => 'Karl-Heinz'
        };

$VAR1 = {
          'name' => 'Haar',
          'ort' => 'Erfurt',
          'plz' => '99081',
          'vname' => 'Franz'
        };

$VAR1 = {
          'name' => 'Huber',
          'vname' => 'Karl-Heinz'
        };

$VAR1 = {
          'name' => 'Kunz',
          'plz' => '55555',
          'vname' => 'Erwin'
        };

View full thread Empfehlung Datenbank als Datei