chiark / gitweb /
Support for resource pools, based on the Apache model.
[mLib] / sym-ref
1 #! /usr/bin/perl
2 #
3 # Reference implementation for symbol table testing.
4
5 %a = ();
6 while (<>) {
7   chomp();
8   @F = split();
9   if ($F[0] eq "set") {
10     $a{$F[1]} = $F[2];
11   } elsif ($F[0] eq "get") {
12     if (exists($a{$F[1]})) {
13       print "$a{$F[1]}\n";
14     } else {
15       print "*MISSING*\n";
16     }
17   } elsif ($F[0] eq "del") {
18     if (exists($a{$F[1]})) {
19       delete($a{$F[1]});
20     } else {
21       print "*MISSING*\n";
22     }
23   } elsif ($F[0] eq "count") {
24     print int(keys(%a)), "\n";
25   } elsif ($F[0] eq "show") {
26     if (!%a) {
27       print "*EMPTY*\n";
28     } else {
29       my $s = "";
30       foreach $k (sort(keys(%a))) {
31         print "$s$k:$a{$k}";
32         $s = " ";
33       }
34       print "\n";
35     }
36   } else {
37     print "*BAD*\n";
38   }
39 }
40