=for story Sally was walking along a path when she came to a very large hole. She filled the hole with sand =cut $hole = 'sand'; =for story As she walked across the hole, she realized she might get lost if she didn't put down some stones to find her way back. She put down a red stone, a blue stone and a white stone: =cut @stone = qw(red blue white); =for story No sooner had she put down the stones than she arrived at a 3-way intersection. Here is the Perl, you tell the story: =cut %directions = ( left => 'Yorkshire', right => 'Birmingham', straight => 'Nottamun' ); %distance = ( Yorkshire => '5 miles', Birmingham => '1.5 miles', Nattamun => '2.2 miles' ); =for story Did you tell the story? I'm sure you figured it out. However, let's have Perl tell it for us: =cut while (my ($direction, $location) = each %directions) { print "if she takes the $direction path, she will walk for $distance{$location} before arriving at $location.\n"; } =for story Ok, now we have ended the first lesson in our Perl storybook. We have learned many things in just one lesson: HOLES: We learned how to fill in holes. Whenever we want to fill in a hole, we just put something in it. The hole is anything that you want to hold a value. Here is one more example: Today is Saturday $today = 'Saturday'; BEADS: When Sally put down the stones on the path, she was storing a series of things to help her later. Whenever you have a list of things you want to keep together, you put them down together, just like putting beads on a necklace. Let's create a list of grocery items: my @shopping_list = qw(oranges apples bananas); DICTIONARIES: You know what a dictionary is right, you look up a key and you get a value. Let's create a dictionary of magic terms: %magic = ( spell => 'something you cast on someone', rabbit => 'something you pull out of a hat', wand => 'the thing you wave to cast a spell' ) Now let's get something out of our dictionary: =cut print $magic{wand}