Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Flock to Rename Directory

by Marshall (Abbot)
on Sep 18, 2009 at 08:23 UTC ( #796047=note: print w/replies, xml ) Need Help??


in reply to Flock to Rename Directory

I think that you are vasty under estimating the complexity of implementing a robust flock (file lock) mechanism by yourself.

You say: Im a novice . Nothing wrong with that, everybody starts. I am saying that this flock() stuff can be a lot more complex in the "always works" details than you think.

There is a big difference between "works all the time" and works "almost all the time". The coordination and sequencing of asynchronous events is hard -> this is NOT something that I would recommend for a self proclaimed novice -> the pitfalls are many!

At the same time, I think that you are over estimating the effort to do some simple SQL statements (Perl is great at SQL stuff!). I think the total amount of SQL related code will be like 1/2 page in your application.

One of the issues with a DB is how to set it up, maintain it, etc.
I recommend the most basic DB, DB::CSV. You will probably also need SQL::Statement and Text::CSV_XS. Unfortunately DB::CSV doesn't work on Windows. I hope that you have a Unix variant to test with.

The rationale behind my recommendation of DB::CSV is to get the SQL part figured out. You will wind up with an application that "works" albiet not as fast as it could. All the SQL code will "port" to the "fancy DB" after you get the basic thing working.

Initailizing the CSV DB is simple, it is a Comma Separate Value file. So this is a text file that can be generated from say an Excel spreadsheet or other ways. Your data has 5 fields, I think the user id is unique although that won't matter if it is not.

This may seem like a "stupid question" on my part, but I am compelled to ask it because it could result in a vast simplification of the problem.
I need to save name, username, time, and two other numerical parameters. You don't need to use a dynamic database update if what is in the database currently doesn't matter. In other words, supplying completely new data for a username is a very different thing than updating info for that user based upon what is was in the DB for that user. If you just want the "latest info" for that username, this is very different than a DB read/update situation. Multiple processes can open a file for append. No need for flock() as long as each "record" is terminated by a "\n", ie a single line of output. If this is the case, then we generate a report/update the main DB file periodically (on demand or very 12 hours, etc). Again, my question sounds "goofy", but it is important to make sure that this is NOT "goofy".

Replies are listed 'Best First'.
Re^2: Flock to Rename Directory
by Anonymous Monk on Sep 18, 2009 at 09:12 UTC
    One of the issues with a DB is how to set it up, maintain it, etc. I recommend the most basic DB, DB::CSV. You will probably also need SQL::Statement and Text::CSV_XS. Unfortunately DB::CSV doesn't work on Windows. I hope that you have a Unix variant to test with.

    DB::CSV doesn't exist. You probably meant DBD::CSV, and I'm pretty sure DBD::CSV does work on windows.

      Yes, I misspoke. DBD:CSV is right. Please forgive me for a minor typo eg (DB:CSV vs DBD:CSV). I am on ActiveState 5.10 and DBD:CSV looks like it is there. On my previous ActiveState version, it wasn't there.

      GREAT! Use this to get SQL working and then upgrade DB as performance requires!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2020-01-24 00:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?