jjw92:

Just a minor quibble: I wouldn't use empty strings to signify missing values. I use the default undef value for that (and in a hash, I'll often not insert the key for a missing value, either). In the general case, you may find that an empty string is a legitimate value, and then you wouldn't be able to tell the difference between a missing value and an intentional empty string.

In the case you've presented, it appears that it wouldn't matter, as an empty string wouldn't normally be a valid value for age, height, weight or sex. But if you had a "nickname" field, for instance, a person with no nickname might be represented with an empty string. So if one of your data sources doesn't provide a nickname, stuffing the nickname with empty strings would imply to your database that those people have no nickname.

Why would it matter? Think of three questions: (1) How many people in your database have nicknames? (2) How many people don't have nicknames? (3) How many people have we asked?

Your method would allow you to answer question 1--mostly. But you couldn't legitimately answer questions 2 or 3. Using undef vs. and empty string would let you answer questions 2 and 3, as well as give you a better answer for question 1 (Out of X people that we've asked, Y have a nickname).

Another way it could matter: In the problem you're solving now, you're merging information from multiple records. If one record is missing a data item, you can overlay the missing field from the other record. But what do you do if there's a conflict between two data items? You'll need to figure out how to resolve those differences. Throw in the fact that a nickname may be explicitly blank, and your code wouldn't be able to tell that the person no longer uses a nickname. Instead, they'll be stuck with their old nickname since you wouldn't be able to overlay it with an empty string--it would be treated as a missing value and ignored...

Sorry for the long, rambling node. I haven't the time to make it short and concise.

...roboticus


In reply to Re: Comparing/Completing Hashes by roboticus
in thread Comparing/Completing Hashes by jjw92

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.