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 ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.