Exercises
See Appendix A for answers to the following exercises:
[7] Write a program that will ask the user for a given name and report the corresponding family name. Use the names of people you know, or (if you spend so much time on the computer that you don’t know any people) use Table 6-1.
Table 6-1. Sample data
Input
Output
fredflintstonebarneyrubblewilmaflintstone[15] Write a program that reads a series of words (with one word per line)[173] until end-of-input, then print a summary of how many times each word was seen. (Hint: remember that when an undefined value is used as if it were a number, Perl automatically converts it to
0. It may help to look back at the earlier exercise that kept a running total.) If the input words werefred,barney,fred,dino,wilma,fred(all on separate lines), the output should tell us thatfredwas seen3times. For extra credit, sort the summary words in ASCII order in the output.
[173] It has to be one word per line because we still haven’t shown you how to extract individual words from a line of input.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access