Skip to Main Content
Learning Perl, 5th Edition
book

Learning Perl, 5th Edition

by Randal L. Schwartz, Tom Phoenix, brian d foy
June 2008
Beginner content levelBeginner
352 pages
11h 16m
English
O'Reilly Media, Inc.
Content preview from Learning Perl, 5th Edition

Exercises

See Appendix A for answers to the following exercises:

  1. [7] Make a pattern that will match three consecutive copies of whatever is currently contained in $what. That is, if $what is fred, your pattern should match fredfredfred. If $what is fred|barney, your pattern should match fredfredbarney or barneyfredfred or barneybarneybarney or many other variations. (Hint: you should set $what at the top of the pattern test program with a statement like my $what = 'fred|barney';.)

  2. [12] Write a program that makes a modified copy of a text file. In the copy, every string Fred (case-insensitive) should be replaced with Larry. (So, Manfred Mann should become ManLarry Mann.) The input filename should be given on the command line (don’t ask the user!), and the output filename should be the corresponding filename ending with .out.

  3. [8] Modify the previous program to change every Fred to Wilma and every Wilma to Fred. Now input like fred&wilma should look like Wilma&Fred in the output.

  4. [10] Extra credit exercise: write a program to add a copyright line to all of your exercise answers so far, by placing a line like:

     ## Copyright (C) 20XX by Yours Truly

    in the file immediately after the “shebang” line. You should edit the files “in place,” keeping a backup. Presume that the program will be invoked with the filenames to edit already on the command line.

  5. [15] Extra extra credit exercise: modify the previous program so that it doesn’t edit the files that already contain the copyright line. (Hint: you ...

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.
Start your free trial

You might also like

Learning Perl, 6th Edition

Learning Perl, 6th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Beginning Perl

Beginning Perl

Curtis Ovid Poe
Learning Perl 6

Learning Perl 6

brian d foy
Mastering Perl

Mastering Perl

brian d foy

Publisher Resources

ISBN: 9780596520106Supplemental ContentErrata Page