17.7. Exercise
See Section A.16, "Answer to Chapter 17 Exercises" for an answer to the following
exercise:
-
[30] Make a program that reads a list of strings from a file, one
string per line, and then lets the user interactively enter patterns
that may match some of the strings. For each pattern, the program
should tell how many strings from the file matched, then which ones
those were. Don't re-read the file for each new pattern; keep
the strings in memory. The filename may be hard-coded in the file. If
a pattern is invalid (for example, if it has unmatched parentheses),
the program should simply report that error and let the user continue
trying patterns. When the user enters a blank line instead of a
pattern, the program should quit. (If you need a file full of
interesting strings to try matching, try the file
sample_text in the files you've surely
downloaded by now from the O'Reilly website; see the
Preface.)
| | | 17.6. Slices | | A. Exercise Answers |
Copyright © 2002 O'Reilly & Associates. All rights reserved.
|
|