package Monitor::Hash;  # file Hash.pm in directory Monitor

# arguments:  package name, reference to initial value of hash, name of
# tied variable (without %)
sub TIEHASH {
   my ($pkg, $rhash, $name) = @_;
   # see comments in TIEARRAY() in Monitor::Array
   my $obj = [$name, {%$rhash}];
   return (bless $obj, $pkg);
}

# argument will be the variable name and a hash key
sub FETCH {
   my ($obj, $index) = @_;
   my $val = $obj->[1]->{$index};
   print STDERR 'Read    $', $obj->[0], "{$index} ... $val\n";
   return $val;
}

# argument will be the variable name, a hash key and its new value
sub STORE {
   my ($obj, $index, $val) = @_;
   print STDERR 'Wrote   $', $obj->[0], "{$index} ... $val\n";
   $obj->[1]->{$index} = $val;
   return $val;
}

1;

