#!/usr/bin/perl -w
# File: Noisy

package NoisyScalar;
sub TIESCALAR { bless \ my $value, shift }
sub STORE {
  my $valref = shift;
  $$valref = shift;
  print "Hey! I was just assigned the value '$$valref'!\n";
}
sub FETCH {
  my $valref = shift;
  print "Yo! You're reading my value, which is '$$valref'!\n";
  return $$valref;
}
sub DESTROY {
  my $valref = shift;
  print "Oh No! I'm being untied! my value is '$$valref'...\n"
}

package main;
$loudmouth = 17;	# Ordinary scalar.
tie $loudmouth, 'NoisyScalar';
$loudmouth = 42;	# Magic scalar.
$x = $loudmouth;
$loudmouth = 'Shut up';
print "x is $x, loudmouth is $loudmouth\n";	# Annoying, eh?
untie $loudmouth;
$x = $loudmouth;
print "x is $x, loudmouth is $loudmouth\n";	# Ordinary again.

