I just need a few more eyes to look at this code and help me determine just what in the world could
possibly be going wrong here. this is a CGI script, by the way.
my $tempfile="/tmp/$$.tmp";
open(DBA, "+< $datafile") or die "Could not read $datafile: $!";
flock(DBA, 2);
seek(DBA, 0, 0);
open(TMPA, "+> $tempfile") or die "Could not open tempfile: $!";
flock(TMPA, 2) or die "ERROR: $!"; # it dies here?
seek(TMPA, 0, 0);
while(<DBA>){
# more code here, etc etc ...
Of course, this is only a small piece of a MUCH larger script I've already written.
I'm opening a datafile and comparing it to some user input,
and then opening a tempfile to write any lines that should
be preserved from DBA. Then I'd rewind both files and
write from TMPA to DBA and then truncate, and close.
Anyhow, the real problem comes in when I try to flock the
temp file. I've put debugging lines in the code with
messages that say things like "I've got this far" or
whatever, after each line. And it gets all the way up
to that flock call to the TMPA filehandle just fine. But if
I let the script try to execute that line, the browser just
sits there and hangs... like it's in a loop or something.
What might be happening here? The first flock call to the DBA filehandle works just fine. I'm pulling my hair out after staring at this code for over an hour now. Please help.
*sobs*
-
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.