arrow has asked for the wisdom of the Perl Monks concerning the following question:
I'm making this administrative website and one of its functions is editing the names of members. The thing is, I have text files containing records of who worked when and for how long, which is separate from my list of members. For example:
Member List
J. Smith D. Smith M. Smith etc...
Records
6/11/2002+J. Smith,D. Smith,M. Smith+2 Format: Date+Members+Hours
If I want to change J. Smith to T. Smith, I can do that with the member list, but not with the records file, because they are in different files. Two solutions for this problem are: 1. Have the script search for all occurances of the name (in both files), then change it to the new one. 2. Assign numbers to the names, and in the records file the members will look like-1,5,7,8-corresponding to the members in the member list, thereby allowing me to concentrate solely on editing the member list. Any better suggestions? Which idea do you like best? Thanks in advance for any assistance.
Just Another Perl Wannabe
Re: Changing records
by graff (Chancellor) on Apr 03, 2003 at 03:25 UTC
|
Your latter idea, assigning ID numbers to people, having "number,name" in one file and "date,number(s),hours" in the other file, is definitely the way to go. This is called normalizing a database -- basically, don't store a piece of "mutable" data in more than one place.
For that matter, don't store more than one name/person-number in a single "hours" record: i.e., it should always be just "date,person_number,hours", one person mentioned per row.
As for better suggestions, try actually using a relational database (e.g. mysql), where this sort of thing is quite natural and easy. (But that's not essential -- for something on this scale, you could just as well use perl hashes to provide the same functionality without breaking a sweat.) | [reply] |
Re: Changing records
by kschwab (Vicar) on Apr 03, 2003 at 03:29 UTC
|
I would go with #2. In technical terms, this is referred
to as database normalization. See this blurb from devshed that explains the benefits.
I'd also recommend using a more easily updated datastore like a tied hash. That will make it easier for you to manipulate records without rewriting the whole file.
Last thought...you may want to look into some sort of
locking mechanism to handle multiple concurrent updates. | [reply] |
Re: Changing records
by pg (Canon) on Apr 03, 2003 at 03:24 UTC
|
Why not database? This kind of flat file system is really difficult to maintain, change file format in the future would be a big hussle.
Using a database system, you would get the searching capability for free.
| [reply] |
Re: Changing records
by DrManhattan (Chaplain) on Apr 03, 2003 at 03:41 UTC
|
| [reply] |
|
I use the members list for other pages, like the View Hours page and the Add Hours page. This keeps me from hardcoding names into the scripts.
Just Another Perl Wannabe
| [reply] |
|
Could you adapt the other scripts to use the records file instead of the members file? That way you'd only have to deal with one data source.
-Matt
| [reply] |
Re: Changing records
by arrow (Friar) on Apr 03, 2003 at 03:51 UTC
|
Yeah, I know, databases are the "bomb", but I don't have the funds to pay for a host that has databases. I'm working strictly with CGI on the internet, so installing mySQL or other is out of the question. I guess flat files are the only thing for me :-{...
Just Another Perl Wannabe | [reply] |
|
| [reply] |
|
|