#!/usr/bin/perl sub putDB { my ($table, $name, $value) = (shift, shift, shift); unless (-e "$table.db") { open (TRG,">$table.db"); print TRG; close(TRG); } if (chkDB($table,$name)) { delDB($table,$name); } $name =~ s/#/&raute;/g; $value =~ s/#/&raute;/g; open (TRG,">>$table.db"); print TRG "$name#$value\n"; close TRG; return 1; } sub delDB { my ($table, $name) = (shift, shift); unless (-e "$table.db") { die "There is no Table with the name '$table'. Died while calling 'delDB'."; return 0; } $name =~ s/#/&raute;/g; my %newtable; open (SRC,"<$table.db"); while () { chomp; my ($n, $v) = split /#/ , $_ if ($_ ne ""); unless ($n eq $name) { $newtable{$n} = $v; } } close(SRC); open (TRG,">$table.db"); foreach my $n (keys %newtable) { print TRG "$n#$newtable{$n}\n"; } close TRG; return 1; } sub chkDB { my ($table, $name) = (shift, shift); unless (-e "$table.db") { die "There is no Table with the name '$table'. Died while calling 'chkDB'."; return 0; } $name =~ s/#/&raute;/g; my $return = 0; open (SRC,"<$table.db"); while () { my ($n, $v) = split /#/ , $_; if ($n eq $name) { $return = 1; } } close(SRC); return $return; } sub getDB { my ($table, $name) = (shift, shift); unless (-e "$table.db") { die "There is no Table with the name '$table'. Died while calling 'getDB'."; return 0; } $name =~ s/#/&raute;/g; my $return = 0; # @return; open (SRC,"<$table.db"); while () { my ($n, $v) = split /#/ , $_; if ($n eq $name) { $v =~ s/\&raute\;/#/g; $return = $v; # push(@return,$v); } } close(SRC); return $return; # @return; } 1;