ebook img

Learning Perl Student Workbook PDF

163 Pages·2012·1.848 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Learning Perl Student Workbook

Student Workbook brian d foy SECOND EDITION Student Workbook for Learning Perl brian d foy Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo Student Workbook for Learning Perl, Second Edition by brian d foy Copyright © 2012 brian d foy. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Editor: Shawn Wallace Cover Designer: Karen Montgomery Production Editor: Melanie Yarbrough Interior Designer: David Futato Illustrator: Robert Romano January 2012: Second Edition. Revision History for the Second Edition: 2012-01-25 First release See http://oreilly.com/catalog/errata.csp?isbn=9781449328061 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Student Workbook for Learning Perl, Second Edition and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein. ISBN: 978-1-449-32806-1 [LSI] 1327515583 Table of Contents Preface ..................................................................... vii Part I. Exercises 1. Introduction ........................................................... 3 2. Scalar Data ............................................................. 5 3. Lists and Arrays ......................................................... 7 4. Subroutines ............................................................ 9 5. Input and Output ...................................................... 11 6. Hashes ............................................................... 15 7. In the World of Regular Expressions ....................................... 17 8. Matching with Regular Expressions ....................................... 19 9. Processing Text with Regular Expressions .................................. 21 10. More Control Structures ................................................. 23 11. Perl Modules .......................................................... 25 12. File Tests ............................................................. 27 13. Directory Operations ................................................... 29 iii 14. Strings and Sorting ..................................................... 31 15. Smart Matching and given-when ......................................... 33 16. Process Management ................................................... 37 17. Some Advanced Perl Techniques .......................................... 39 18. Databases ............................................................ 41 Part II. Answers A. Answers to Chapter 1 Exercises ........................................... 45 B. Answers to Chapter 2 Exercises ........................................... 49 C. Answers to Chapter 3 Exercises ........................................... 55 D. Answers to Chapter 4 Exercises ........................................... 59 E. Answers to Chapter 5 Exercises ........................................... 65 F. Answers to Chapter 6 Exercises ........................................... 75 G. Answers to Chapter 7 Exercises ........................................... 81 H. Answers to Chapter 8 Exercises ........................................... 89 I. Answers to Chapter 9 Exercises ........................................... 95 J. Answers to Chapter 10 Exercises ......................................... 101 K. Answers to Chapter 11 Exercises ......................................... 107 L. Answers to Chapter 12 Exercises ......................................... 113 M. Answers to Chapter 13 Exercises ......................................... 121 N. Answers to Chapter 14 Exercises ......................................... 127 iv | Table of Contents O. Answers to Chapter 15 Exercises ......................................... 131 P. Answers to Chapter 16 Exercises ......................................... 137 Q. Answers to Chapter 17 Exercises ......................................... 143 R. Answers to Chapter 18 Exercises ......................................... 149 Table of Contents | v Preface This workbook is an additional set of exercises to supplement those already in Learning Perl, Sixth Edition. The chapter and page references apply only to that edition. Addi- tionally, unless I denote otherwise, Learning Perl without qualification means the sixth edition. That book already contains some exercises, and I try to cover the topics those exercises didn’t. I’ve been teaching Perl since 1998, and my beginner classes use Learning Perl as the course text. Along the way, I’ve posed a lot of additional problems to students so they could test their understanding of the topics I covered and some of the additional in- formation I added in the lecture. In doing this, I pose two sorts of problems: one of simple knowledge where knowing the right fact or trick makes the problem easy, and the other somewhat clever where a Perl implementation of a particular technique solves the problem. I’ve tried to include both of those sorts of problems in this book. You should find some exercises are easy, some require that you find nuggets of infor- mation you may have missed on a first reading of Learning Perl, and others require you know something about algorithms or programming that aren’t simply a question of Perl knowledge and might require you to do some research on your own. As you learn about how to learn about Perl, whether through its documentation or online resources, I pose these challenging problems expecting that you’ll use everything available to you. There’s a lot more to programming than just the syntax. This isn’t a classroom and you aren’t being graded, unless it is a classroom and you are being graded. I won’t think you are cheating if you use Google, and you shouldn’t feel that you have to come up with everything just by staring at a blank document. If someone is grading you, just show them this paragraph and tell them I say it’s okay. If you’re the instructor, fear not: no one reads the preface anyway, especially if it’s not on the test. You should be able to complete most of the exercises with Perl 5.8, and I expect that you might even be able to use Perl 5.004, a quite ancient version indeed. Some of the exercises require a minimum version of Perl because I want you to use a particular feature introduced in that version, and I’ll note the minimum version in the exercise when it’s appropriate. If you don’t note a minimum version assume that it’s at least vii Perl 5.8. I’d prefer that you use a supported version of Perl, which at this writing is at least Perl 5.14. However, I know that some of you don’t get to make that choice. Perl’s motto, for good or bad, is “There’s More Than One Way To Do It”, so don’t take my solutions as gospel. Remember that the corollary to that is “But most of them are wrong”, so don’t go out of your way to avoid techniques that I show. I show you a way to do it, and often I give you more than one way to do it. However, if you accom- plished the task and your solution doesn’t look remotely similar to mine, that’s okay (probably). Some of my answers have extra material that show techniques you’ll read about in later chapters. I don’t expect you to use those techniques, but I show them because they are the techniques and features you’ll use in everyday programming once you finish the book. They are just a taste of things to come. viii | Preface PART I Exercises • Chapter 1 Introduction • Chapter 2 Scalar Data • Chapter 3 Lists and Arrays • Chapter 4 Subroutines • Chapter 5 Input and Output • Chapter 6 Hashes • Chapter 7 In the World of Regular Expressions • Chapter 8 Matching with Regular Expressions • Chapter 9 Processing Text with Regular Expressions • Chapter 10 More Control Structures • Chapter 11 Perl Modules • Chapter 12 File Tests • Chapter 13 Directory Operations • Chapter 14 Strings and Sorting • Chapter 15 Smart Matching and given-when • Chapter 16 Process Management • Chapter 17 Some Advanced Perl Techniques • Chapter 18 Databases (bonus chapter)

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.