#!/usr/bin/perl use strict; use warnings; use Tie::File; use Tie::Watch; $main::touched=0; my @array; my $file='test_tie_file'; sub touched {$main::touched=1} push @array, int (rand 1000) until $#array > 39; # fill it on the first pass my $watch = Tie::Watch->new( -variable => \@array, -debug => 0, -shadow => 1, -fetch => sub {print "Fetch\n"; my $self=shift; $self->Fetch}, -store => sub {print "Store\n"; $main::touched=1; my $self=shift; $self->Store (@_)}, -push => sub {print "Push\n"; $main::touched=1; my $self=shift; $self->Push (@_)}, -clear => sub {print "Clear\n"; $main::touched=1; my $self=shift; $self->Clear (@_)}, -extend => sub {print "Extend\n"; $main::touched=1; my $self=shift; $self->Extend (@_)}, ); tie @array, 'Tie::File', $file or die "cannot tie to $file: $!\n"; $main::touched=0; print "array of length $#array is now watched\n"; print "would you like to alter the file (y/n)\n"; my $ansa=; push @array, 'touched' if $ansa =~/^y/; untie @array; $watch->Unwatch; if ($main::touched) { print "File has been altered\n" } else { print "File remains the same\n"; }