CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
Adding New Record



Jun 27, 2000, 7:10 AM

Post #1 of 4 (6581 views)
Adding New Record Can't Post

Can anyone here please tell me how do I add new record between two existing records in flat file database?

Example :

Record Line 1
Record Line 2

I need to add new record in between line 1 and line 2 instead of under line 2, please help, thanks.


Jun 27, 2000, 4:54 PM

Post #2 of 4 (6581 views)
Re: Adding New Record [In reply to] Can't Post

Open the existing file as input and a new file as output. Read thru the existing file writing to the output file as you're going. Write the new record into the output file where you want it. At the end close the files and then rename the new file to the same name as the old file so that it takes over as the existing file.


Jun 27, 2000, 7:25 PM

Post #3 of 4 (6581 views)
Re: Adding New Record [In reply to] Can't Post

Thank you, this really help me a lot...brilliant idea...thanks again


Jul 5, 2000, 7:50 PM

Post #4 of 4 (6581 views)
Re: Adding New Record [In reply to] Can't Post

Another case of RTFFAQ
How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?

A filesystem has no concept of a "line".
To insert a line, you either need to rewrite the whole thing, or use something like DB_File and tie the file to an array.
Also consider DBD::CSV if you really want a flat file database.. You get some basic functionality.

DB_File docs at or of course perldoc DB_File from the command line. Its standard distro.

DBD::CSV docs at You would need to install DBI and DBD but then you get a pretty cool text database


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives