Here's an example.
use POSIX qw( LOCK_EX SEEK_SET ); # Open a shared file for reading and writing open my $fh, '<+', $filename or die "Can't open $filename for reading: $!"; flock $fh, LOCK_EX | LOCK_NB or die "Can't get an exclusive lock on $filename: $!"; # Read one line. my $contents = <$fh>; # Empty the file. seek $fh, 0, SEEK_SET or die "Can't seek to the start of $filename: $!"; truncate $fh, 0 or die "Can't truncate $filename: $!"; # Put something new in there. print $fh "...." or die "Can't write to $filename: $!"; close $fh or die "Can't write to $filename: $!";
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
In reply to Re^4: File Read
by diotalevi
in thread File Read
by rheaton
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |