Next Tricks of the Wizards 56

Tied Scalar Example

        package Sequence;
        sub TIESCALAR {
          my ($package, $start) = @_;
          $start = 1 unless defined $start;
          my $object = {VALUE => $start};
          bless $object => $package;
        }
        sub FETCH {
          my ($self) = @_;
          $self->{VALUE}++;
        }
        sub STORE {
          my ($self, $newvalue) = @_;
          $self->{VALUE} = $newvalue;
        }


Next Copyright © 2003 M. J. Dominus