Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flat File Updater?

Status
Not open for further replies.

wyshmasta

Programmer
Oct 24, 2003
3
US
Hi - Here is my question:

I am running on on Windows IIS 6.0 server and I have installed a flat file database in ASP.. However the Update/Delete records function does not work (I used The BreezeBase from breezebase.com). So I decided that maybe I should create an Update/Delete script in Perl because I know perl better than I know ASP. I have absolutely no Idea where to begin.

The entire database runs from one .txt file where all the entries are stored. One entry per line with the pipe "|" delimeter.

What I need is a Perl Script that can allow someone to Search for the entry they want to update... then the script will show the entry and allow them to update/change or delete that entry only and then allow them to save it back to the raw text file. Kinda like a GUI script. This is over my head as far as programming it from scratch. If anyone knows where I can find a script like this or any help at all would be appreciated.

Thanks.
Mike
 
I assume an entry is unique in the file e.g.
the file is like
entryid1 |val|val|val|
entryid2 |val|val|val|val|val|
entryid3 |val|val|
Because the record size is variable you have to:
1. Load the whole file in a hash array in memory
2. Ask user to type entry to be updated/deleted
3. Locate the entry id in the array
4. Ask choose delete or update
5. If delete then delete the entry from the array
6. If update then split the rest of the record in array of fields
7. Iterate through all fields and display for each the field name , its value and ask user
for the new value:
Fieldname : original value -> new value : _
Replace original value by new value in the array of fields
8. When there are no more delete/updates
9. Create a .new file from the updated hash array
10. If the creation was successful then
-delete the original file name
-rename .new file into the original file name

Another easy solution is using Excel:
1. Open the file as text delimited file
2. Find entry - to locate the row that contains a given entry . Then modify/delete row
3. Save the file as a delimitted text file

-obislavu-
 
A good (easy, extensible) way to update text files using Perl is The DBI -- there's a DBD::CSV driver that makes updating, deleting, selecting rows from a text file as easy as with a big database.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top