Minute Three: In Your Mailbox

Let's slow down for this third minute. We can't have your friend harassing you any further or you'll be storming off soon.

Instead, we're going to take a walk and pick up the mail. You live in an apartment complex and your mailbox is a little slot next to hundreds of other slots.

You check your mailbox and find that you have five items of mail. Two for your neighbor, Jim O'Connor, and one for a business called "Hank Bros.: the Car Wash!". The other two letters are for you.

You decide to start keeping a record of the items you find in your mailbox. You're going to send a detailed report to the post office so they can see what a mess this is for you.

You start a new YAML document with today's date and the contents of your mailbox:

---
date: 2003-07-25
letters to:
  "Hank Bros.: the Car Wash!": 1
  Jim O'Connor: 2
  Myself: 2

Here we have a map inside of another map. The first map contains a key: letters to. The value for this key is a nested map, which is indented.

In PHP or Ruby:

print $mailbox['letters to']['Myself'];

Would print:

2 

You'll also notice that we've quoted "Hank Bros.: the Car Wash!". This is because the name includes a colon. Some characters need to be quoted to ensure that there is no confusion about what is a key and what is a value.

Almost there! MinuteFour

Last edited Dec 21, 2009 at 8:09 PM by BurtHarris, version 3

Comments

havenskys Feb 12, 2009 at 8:38 PM 
Please advise, should the 'indented' nested map be any perticular type of white space (space, number of spaces, or tab)