<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">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-&gt;[1]-&gt;{$index};
   print STDERR 'Read    $', $obj-&gt;[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-&gt;[0], "{$index} ... $val\n";
   $obj-&gt;[1]-&gt;{$index} = $val;
   return $val;
}

1;

</pre></body></html>