in reply to Comparing/Completing Hashes
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing/Completing Hashes
by jjw92 (Novice) on Aug 14, 2010 at 00:42 UTC |