#!/usr/bin/perl use strict; use warnings; package Sensitive_Array; { use Carp; use strict; sub TIEARRAY { my $class = shift; my $aref = shift; if ( @_ ) { croak "usage: tie ARRAY, '" . __PACKAGE__ . "', ArrayRef"; } return bless $aref, $class; } sub FETCH { my $self = shift; my $index = shift; print " Fetch "; return $self->[$index]; } # STORE this, index, value sub STORE { my $self = shift; my( $index, $value ) = @_; print " Store "; $main::touched=1; $self->[$index]=$value; } # FETCHSIZE this sub FETCHSIZE { my $self = shift; print " Fetchsize "; return scalar @{$self}; } # STORESIZE this, count # I think this is right but please check ! sub STORESIZE { my $self = shift; my $count = shift; $main::touched=1; print " Storesize "; $#{$self} = $count -1 ; } # EXTEND this, count sub EXTEND { my $self = shift; my $count = shift; $main::touched=1; print " Extend "; $self->STORESIZE( $count ); } # PUSH this, LIST sub PUSH { my $self = shift; my @list = @_; $main::touched=1; print " Push "; push @$self, @list; } # POP this sub POP { my $self = shift; $main::touched=1; print " Pop "; return pop @{$self}; } # SHIFT this sub SHIFT { my $self = shift; $main::touched=1; print " Shift "; return shift @{$self}; } # UNSHIFT this, LIST sub UNSHIFT { print " not implemented "; } # SPLICE this, offset, length, LIST sub SPLICE { print " not implemented "; } # UNTIE this # DESTROY this }; 1;