O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

An Example: More Names

On Day 5, we had a simple example that read in names (first and last), and then split those names into a hash of names keyed by the last name. On Day 6, both in the body of the lesson and in the exercises, we used the <> operator to read those names into a hash from an external file. Let's extend the names script here so that it doesn't just read the names into a hash, it also does something with those names. This version of the names script, morenames.pl, adds a large while loop that gives you a list of four options:

  • Sort and print the names list by last name

  • Sort and print the names list by first name

  • Search for first or last name

  • Quit

If you choose any of the options to search or sort the list, the program repeats and allows ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required