If you insist on using a "flat file", which I assume means line-delimited records in an ordinary file, then the fastest (programmers') way to delete or insert a record is to read the file into an array (Perl will read it automatically into your array with line-delimiters as default), switch it in your script with the whole file in MEM and rewrite the file. Of course, this is not the optimal solution. The optimal solution involves moving (on average) 50% of all data sets in the file to delete and none to append. To delete, find the line where you want the deletion to begin/end and copy the rest of the file "up". Another solution would be to comment it out in some manner and "optimize" you crappy database on a cron cycle by deleting comments from the file every so often. Edit is yet more complicated since it may involve reducing or enlarging the file depending on how much input is given. Of course, as the others said, this is very strange limiting situation and it would be extraordinarily easy to convert your text file to a form of
AnyDBM_File, which is the recommended solution if you're not running a dbengine. Since this is CGI, as you mentioned, you'll want to be careful what the user passes you- perhaps max line lengths, valid chars, etc.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.