| |||||||
|
|
Click here to download plain text source code.
# subroutine name: writehash # Input: filename, hash reference # Writes hash to file in format: <key>\t<value> # # Global variables used: # $no_flock - disable flock or not sub writehash { my($datafile,$r_rows) = @_; GetFileLock("$datafile.lock"); use Fcntl qw( O_RDWR O_WRONLY O_CREAT O_TRUNC ); local *DATA; if (sysopen(DATA, $datafile, &O_WRONLY | &O_CREAT)) { flock(DATA, 2) unless ($no_flock); truncate(DATA, 0) or die "Can't truncate $datafile. Reason: $!"; foreach (keys %$r_rows) { print DATA safe_tbl($_)."\t".safe_tbl(${$r_rows}{$_})."\n"; } flock(DATA, 8) unless ($no_flock); close(DATA); chmod(0666,$datafile); ReleaseFileLock("$datafile.lock"); } else { ReleaseFileLock("$datafile.lock"); die("Error in subroutine writehash: Can't open $datafile. Reason: $!"); } } |
|||||||||||||||||||||
| Copyright © 1999-2007 Atomicsoft Ltd. All Rights Reserved. | ||