Perl Home Notes Exercises Resources perl Thoughts Jen's Home Summer Perl Seminar

Week 3 Exercises

Exercise 1

We searched through Ken Lay's emails for addresses and phone numbers. Now search it for email addresses. You can start with a simple pattern of non-space characters, but refine it as you see things that don't make sense. As you refine, be sure to allow for dots, dashes, and underscores but not other punctuation.

Exercise 2 (Hard)

Going through the Ken Lay Emails, you will see each message starts with a To: and a From:. Build a list like the one I supplied last week where, for each email, you print a line that lists the sender and recipient: bob@example.com,joe@example.com alice@example.com,eve@example.com joe@example.com,eve@example.com Hint: The To: always comes after the From:. You will have to add some variable to keep track of whether you have already seen the From: of the message and are looking for the To:, or if you have seen a To: and are now looking for a From: again.

Exercise 3

Why is this funny?
/bb|[^b]{2}/

Exercise 4 (Easy)

Here are some simple exercises for you to try. For each, start with the string below and write a script to see if the string matches the given pattern. $string = "Lasciate ogne speranza, voi ch'intrate";
  • Does the string contain the letter t?
  • Is there a word containing the letter e.
  • Find text that starts with an "a" and ends with a "z".
  • Find a substring that contains two vowels in a row.