1 2 3 4 5 6 7
use Fcntl qw( LOCK_SH SEEK_SET ); open my $fh, '<', $file die $!; flock $fh, LOCK_SH or die $!; seek $fh, 0, SEEK_SET or die $!; my $d = do { local $/; <$fh> }; close $fh;
1 2 3 4 5
open my $fh, '>', $file or die $!; flock $fh, LOCK_EX or die $!; seek $fh, 0, SEEK_END or die $!; print $fh $json; close $fh;
1 2 3 4 5 6 7 8 9 10
# specify file with content my $file = "bla.dat"; # open in (over)write mode clears the file! open my $fh, '>', $file or die "open($file,w) failed: $!"; # look at the file now, you have some time sleep 60; close $fh or die "close($file,w) failed: $!";