#!/usr/bin/perl use strict; use warnings; use Storable qw(retrieve store retrieve_fd store_fd); use Fcntl qw(:flock); my $file='/tmp/storable_test'; my %data = ( item => 'Here I am', ); store(\%data, $file); #===== # open & lock file open(my $fh, '+<', $file); flock($fh, LOCK_EX); # get data, amend, put back my $data = retrieve_fd(\*$fh); print 'item: ', $data->{item},$/; delete($data->{item}); print 'gone (error as expected): ', $data->{item},$/; truncate $fh, 0; # <- *** WAS MISSING THIS *** seek $fh, 0, 0; # <- *** WAS MISSING THIS *** store_fd($data, \*$fh); close($fh); #====== # now reload from the file my $check_data = retrieve($file); print 'why is this here? ', $check_data->{item},$/;