15.5. Exercises
See Section A.14, "Answers to Chapter 15 Exercises" for answers to the following
exercises:
-
[10] Write a program to read in a list of numbers and sort them
numerically, printing out the resulting list in a right-justified
column. Try it out on this sample data, or use the file
numbers, from the O'Reilly web site (see
the Preface):
17 1000 04 1.50 3.14159 -10 1.5 4 2001 90210 666
-
[15] Make a program that will print the following hash's data
sorted in case-insensitive alphabetical order by last name. When the
last names are the same, sort those by first name (again, without
regard for case). That is, the first name in the output should be
Fred's, while the last one should be Betty's. All of the
people with the same family name should be grouped together.
Don't alter the data. The names should be printed with the same
capitalization as shown here. (You can find the source code to create
a hash like this in the file sortable_hash with
the other downloaded files.)
my %last_name = qw{
fred flintstone Wilma Flintstone Barney Rubble
betty rubble Bamm-Bamm Rubble PEBBLES FLINTSTONE
};
-
[15] Make a program that looks through a given string for every
occurrence of a given substring, printing out the positions where the
substring is found. For example, given the input string
"This is a test." and the substring
"is", it should report positions
2 and 5. If the substring were
"a", it should report 8. What
does it report if the substring is "t"?
| | | 15.4. Advanced Sorting | | 16. Simple Databases |
Copyright © 2002 O'Reilly & Associates. All rights reserved.
|
|