Minute One: A Simple List

Your friend e-mails you a list of books:

- Memoirs Found in a Bathtub
- Snow Crash
- Ghost World

He has also requested that you read them in the order listed. He wants to talk to you about them in order as you read them. He's kind of anal.

In YAML, this sort of list is called a sequence. A sequence provides a set of data and gives it an order. When you load this list into your program, the order is kept.

In many agile languages, you can access a sequence by using a numeric index. An index of 0 indicates the first item in a sequence. In PHP, Perl, or Ruby:

print $book_list[0];

Would print:

Memoirs Found in a Bathtub

Which is the first item in the book list.

More Lists

Lists can contain all sorts of data:

- 1           # Numbers
- Snow Crash  # Strings
- 2003-07-24  # Dates

The above list is preceded by three dashes. These three dashes are the document separator. A document separator can indicate the start of a YAML document.

It can also separate multiple documents. You have your own stack of books that you want to read first:

- Harry Potter and the Prisoner of Azkaban
- Harry Potter and the Goblet of Fire
- Harry Potter and the Order of the Phoenix
- Memoirs Found in a Bathtub
- Snow Crash
- Ghost World

On to YamlInFiveMinutesMinuteTwo

Last edited Jan 19, 2009 at 7:52 PM by BurtHarris, version 1


No comments yet.