Exercises

16.5 Exercises

These exercises are all related; it may be helpful to see what the second and third should do before starting on the first. See Section A.15 for answers.

1.       [15] Make a program that will read through the perlfunc.pod file looking for identifier names on =item lines (as in the similar exercise at the end of Chapter 9). The program should write a database showing the first line number on which each identifier appears. That is, if fred was mentioned on lines 23, 29, and 54, the value stored under the key fred would be 23. (Hint: the special $. variable gives the line number of the line that was just read.)

2.       [10] Make a program that will take a Perl function name on the command line, and report what =item line of the perlfunc.pod file first mentions that function. Your program should not have to read through a long file to get this answer. What should your program do if the function name isn't found?

3.       [10] (Extra credit exercise.) Modify the program from the previous exercise so that when the function is found in the database, your program will launch your favorite pager program to view the perlfunc.pod file at that line. (Hint: many programs that can be used for viewing text files work like less does, with a command line like less +1234filename to start viewing the file at line 1234. Your favorite text editor may also support this convention, which is also used by more, pico, vi, emacs, and view.)

 



Learning Perl
Learning Perl, 5th Edition
ISBN: 0596520107
EAN: 2147483647
Year: 2001
Pages: 205

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net