Fellow Monks, I've got a flat file database that I need to be able to edit. Right now, I have a system that works as follows: Each line in the database is numbered. A cgi spits out a HTML page with the entire contents of the database. Beside each line is a link containing a parameter to be passed to the cgi. That parameter is the line number of the database. When passed to the cgi, the cgi works something like this (example code only, not actual code from site):
my $number = $cgi->param('number'); open(DATABASE, "database.dat") || die "Couldn't open the database for +reading: $!"; @database=<DATABASE>; close(DATABASE); my @data = split(/\|/, $database[$number]); # Do all my manipulations here $database[$number] = join('|', @data); open(DATABASE, ">database.dat") || die "Couldn't open the database for + writing: $!"; foreach (@database) { chomp; print DATABASE "$_\n" if ($_ ne ""); } close(DATABASE);

It seems to me that this is a bit error/bug prone. Is there a better way to do this? There is also the remote possibility that I may get multiple users on this system in which I am sure this system would fail. Could anyone tell me a more secure way to do this?

I'm a self-taught programmer. I have no formal training what-so-ever. Any suggestions as to how I could improve both my system and my code would be greatly appreciated! Thanks!

Stamp_Guy
Computers aren't intelligent, they just think they are.


In reply to Flat File Editing Question by Stamp_Guy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.