Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Mysterious Disapperance of file contents

by sgifford (Prior)
on Aug 29, 2003 at 02:45 UTC ( [id://287575]=note: print w/replies, xml ) Need Help??


in reply to Mysterious Disapperance of file contents

What you've posted so far looks fine. What do writedate and release_lock look like?

One good way to do this is to create the new count in a different file, then rename it in to the actual name. You probably have a moment when the file is empty, and if the program crashes just then it will stay empty. By using rename instead, the file is never empty; it is either the old value, or the new value.

Another way is to open the file read-write, read the value, then rewind and write the new value. As long as the number is reasonably short (less than 1000 digits or so) and buffered writes are turned off (or you use syswrite), this should be atomic as well.

Why do you do these two lines?

open(MFILE, ">>$completeadd") || die "file open1 failed: $!\n"; close(MFILE);

Replies are listed 'Best First'.
Re: Re: Mysterious Disapperance of file contents
by belg4mit (Prior) on Aug 29, 2003 at 05:00 UTC
    In which case, there's no sense reinventing wheels.

    --
    I'm not belgian but I play one on TV.

Re: Re: Mysterious Disapperance of file contents
by dtr (Scribe) on Aug 29, 2003 at 15:40 UTC

    The effect of these two lines will be so that when you run the script for the first time, the open(filehandle, filename) || die doesn't die because the file does not exist.

    Otherwise, the script would die continuously until you manually created the file. In theory, the ">>" (append) should prevent data from being overwritten in the file if it does exist and you crash with an open filehandle - although that's perhaps not the safest way of doing things.

    Try removing these lines, and putting a &CreateFile() unless -e $filename; earlier on in the code instead.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://287575]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-26 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found