in reply to the manuals fail me
use Fcntl qw( LOCK_EX O_RDWR O_CREAT SEEK_SET ); my $qfn = '/tmp/myfile.index'; sysopen(my $fh, $qfn, O_RDWR|O_CREAT, 0666) or die("Can't create or open \"$qfn\": $!\n"); flock($fh, LOCK_EX); my $index = <$fh>; ++$index; seek($fh, 0, SEEK_SET); print($fh "$index\n"); #truncate($fh, tell($fh));
You could also do it without locking:
my $qfn = '/tmp/myfile.index'; open(my $fh, '<', $qfn) or die("Can't open \"$qfn\": $!\n"); my $index = <$fh>; ++$index; open($fh, '>', $qfn) or die("Can't create \"$qfn\": $!\n"); print($fh "$index\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: the manuals fail me
by Anonymous Monk on Mar 29, 2012 at 19:24 UTC | |
by ikegami (Patriarch) on Apr 04, 2012 at 20:00 UTC | |
by Anonymous Monk on Mar 30, 2012 at 03:49 UTC |