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*
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.