in reply to Read entire file then clear while flocking

I think you want truncate, as in the untested code below:
use autodie; use Fcntl ':flock', ':seek'; open my $fh, "+<", "mail"; flock $fh, LOCK_EX; my $text = do {local $/; <$fh>}; seek $fh, SEEK_SET, 0; # Only needed if you're going to write. truncate $fh, 0; close $fh;

Replies are listed 'Best First'.
Re^2: Read entire file then clear while flocking
by repellent (Priest) on Nov 05, 2011 at 22:12 UTC
    POSITION and WHENCE reversed - it ought to be: seek $fh, 0, SEEK_SET;