Yes, that's exactly what merlyn is trying to get across. A database is pretty useless if you are only storing a single value. Much easier to simply manage a flat file and be able to read it into an array. A database becomes useful when you need to associate one piece of data with another.

For your example, you are not associating anything with the name. All you have is a name. No age, email adress, phone number, or anything related to the user. If you did have anything, you'd then be using something like this:

# I've never really used a dbm. # They allow complicated structures, right? $dbm{$name}{'age'} = 29; $dbm{$name}{'email'} = 'nobody@example.com';

For a single value, I'd probably use something like this. It could use a little more work :)

use Fcntl ':flock'; sub add_names { my @add = @_; open my $fh, '+<', 'names.dat'; flock $fh, LOCK_EX; chomp( my @names = <$fh> ); seek $fh, 0, 2; for my $name (@add) { warn "$name is already in file" and next if grep { /^$name$/i } @names; print $fh "$name\n"; } close $fh; } sub get_names { open my $fh, '<', 'names.dat'; chomp( my @names = <$fh> ); close $fh; return @names; } sub del_names { my @del = @_; open my $fh, '+<', 'names.dat'; flock $fh, LOCK_EX; chomp( my @names = <$fh> ); truncate $fh, 0; seek $fh, 0, 0; for my $name (@names) { print $fh "$name\n" unless grep { /^$name$/i } @del; } close $fh; }


If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.


In reply to Re^3: Database storage confusion by Coruscate
in thread Database storage confusion by sulfericacid

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.