home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeLearning Perl, 3rd EditionSearch this book

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, "Answers to Chapter 16 Exercises" 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, "Using Regular Expressions"). 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 +1234 filename 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.)



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.