I am working on a unix system (FreeBSD), and thanks for the semaphore pointer (further explained
here).
I guess I'm just surprised that the above doesn't work. As I test and test and re-test I am completely duped that even this simple code doesn't work...
#!/usr/bin/perl -w
# start with no existing giant.db file
use strict;
use Fcntl qw(:DEFAULT :flock);
use Storable qw(store_fd fd_retrieve retrieve);
use Data::Dumper;
$Data::Dumper::Deepcopy=1;
$Data::Dumper::Purity=1;
$Data::Dumper::Sortkeys=1;
my %data = ( 1 => 'FEE', 2 => 'FYE',
3 => 'FOH', 4 => 'FUM', );
sysopen(*DB, "giant.db", O_RDWR|O_CREAT, 0666) or die("sysopen: $!\n")
+;
flock(*DB, LOCK_EX) or die("flock: $!\n");
my $hashref = fd_retrieve(*DB);
# modify the data, do work, etc..
$hashref->{$_} = $data{$_} for sort keys %data;
store_fd($hashref, *DB) or die("store_fd: $!\n");
truncate(*DB, tell(*DB));
close(*DB);
I'm totally spent and frustrated. Does anyone have any idea why this doesn't work? I must be missing something. I'm just trying to block access to a file while I change it. The above SHOULD work, shouldn't it?....shouldn't it?....please?
Thanks
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.