Yes, I know someone just posted a "reading a DBM" question, but this is a little different than his problem. Actually, it makes me feel like a stupid n00b because I'm probably missing something really simple.

I am using the following code to read a list of names from a DBM file. All I want to do is see if a name exists in the list. As such, the DBM file Is just a name followed by the number 1 on each line. This is the code I use to check for a specific name:

#!/usr/bin/perl -w use strict; use DB_File; my %names; tie %names, 'DB_File', 'names.db' || die "$!"; print $names{'drew'}

Whenever I do that, I get "Use of uninitialized value in print." However, when I use the following code to iterate through the names, I get the entire list:

while(my ($key, $value) = each(%names)) { print "$key\t".$names{$key}."\n"; }

I know I'm doing something wrong, but I can't quite figure out what it is. Of course if there's an easier way to do this, I'd be glad to hear it too.


In reply to Can't seem to read DBM by dirtdart

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.