package Number; use strict; use warnings; use IO::File; use Fcntl ':flock'; use Cwd; sub new{ my $class = shift; my $self = bless{}, $class; return eval{ my $file = $class.".pm"; $self->{POS} = tell DATA; $self->{BUF} = ''; read DATA, $self->{BUF}, 32; $self->{NR} = unpack "A32", $self->{BUF}; $self->{FH} = new IO::File; my $dir = getcwd(); $self->{FH}->open("$dir/$file", O_RDWR) or die "IO-Error: $!"; flock $self->{FH}, LOCK_EX or warn "Your system does not support flock"; $self; }; } sub nr{ my $self = shift; return $self->{NR}++; } sub DESTROY{ my $self = shift; $self->{FH}->seek($self->{POS}, 0); $self->{FH}->print(pack "A32", $self->{NR}); } 1; __DATA__ 124