Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: How to modify/delete records in a flat-file database?

by paulbort (Hermit)
on Apr 28, 2004 at 16:53 UTC ( [id://348881]=note: print w/replies, xml ) Need Help??


in reply to How to modify/delete records in a flat-file database?

Some sort of database with transactional integrity would also be my first thought, but if you need to support multiple users making changes, and you can't change the format of the file (because you're interacting with something else, etc.), there is another way to get pretty close to insuring integrity: use another set of files to allow only one 'user' to change the file at a time.

For example, if a program wants to change the file, it checks that directory for glob( 'flat_file_lock_*' ), and if it finds any files, it adds one to the last file name, and touches that file. If it doesn't find any, it touches 'flat_file_lock_0'. (Yes I know there's a race condition here, but if that's an issue, use a database.)

Then each program just needs to wait until it is the lowest-numbered lock file, make its change, and delete its lock file. Primitive but functional.

Another way would be to write your updates to a pipe, and have a separate process listen on that pipe. (Assuming you're not on Windows, where pipes are scary.)

--
Spring: Forces, Coiled Again!
  • Comment on Re: How to modify/delete records in a flat-file database?

Replies are listed 'Best First'.
Re: Re: How to modify/delete records in a flat-file database?
by JoeJaz (Monk) on Apr 28, 2004 at 17:21 UTC
    That is an interesting model. That sounds kind of like a semaphore for operating system process scheduling. Very unique to use that in this way. The pipe idea is something that I will look into also. Thanks for your time and ideas. Joe

Log In?
Username:
Password:

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

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

    No recent polls found