in reply to DBM keys/values

Well, the basic principle of hashes is that there's one value to one key, so you have to cheat. In this case, just store a stringified list (e.g. using join) as the value. Untested example code:
my @unverified_emails=('test@admin.com', '1xtrsnf'); $dbm{'notverified'}=join ",",@unverified_emails; foreach my $mail (split /,/, $dbm{'notverified'}) { print "$mail is not verified!\n"; }
Joining with comma's is probably best, as I've never encountered an email address with one in it. That said, it is not actually illegal to include comma's in email addresses (as long as you escape them with backslashes, see RFC819), so there is a very small possibility you might need another string to delimit the addresses.

Update:One way to take into account backslashed commas is a negative zero width lookbehind assertion in the split regexp: /(?<!\\),/.

CU
Robartes-

Replies are listed 'Best First'.
Re: Re: DBM keys/values
by sulfericacid (Deacon) on Feb 13, 2003 at 04:46 UTC
    This is my first database and in reality one of the first times of having to play with hashes. I didn't realise you couldn't store more than one value per key in a more basic way, it seems to me there would be a lot of use for it if it were built in so you wouldn't need to join/split.

    If your example is implemented would there be a way to choose which value to pull back or would you be stuck pulling both values for @unverified_emails?

    Thanks for your help!



    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
      Well, the restriction here is that you're storing stuff in an underlying DBM database, so you're stuck with one value per key. That's why you need to do join/split or whatever tricks.

      Otherwise, one would use a hash of hashes to store this information (as it's easier to search for stuff in a hash, so it makes sense to store the email addresses themselves in hashes as well). You could store something like this in DBM, but they you would be looking at bronto's suggestion of using serialisation techniques to flatten the data structure before storing it.

      CU
      Robartes-