Tải bản đầy đủ (.pdf) (748 trang)

Beginning Perl doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (7.42 MB, 748 trang )

www.it-ebooks.info
ffirs.indd iiffirs.indd ii 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
BEGINNING PERL
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
CHAPTER 1 What Is Perl? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
CHAPTER 2 Understanding the CPAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
CHAPTER 3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41
CHAPTER 4 Working with Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
CHAPTER 5 Control Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
CHAPTER 6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
CHAPTER 7 Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
CHAPTER 8 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
CHAPTER 9 Files and Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
CHAPTER 10 sort, map, and grep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
CHAPTER 11 Packages and Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
CHAPTER 12 Object Oriented Perl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
CHAPTER 13 Moose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
CHAPTER 14 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
CHAPTER 15 The Interwebs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
CHAPTER 16 Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
CHAPTER 17 Plays Well with Others. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
CHAPTER 18 Common Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
CHAPTER 19 The Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
APPENDIX Answers to Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
ffirs.indd iffirs.indd i 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
ffirs.indd iiffirs.indd ii 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
BEGINNING


Perl
ffirs.indd iiiffirs.indd iii 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
ffirs.indd ivffirs.indd iv 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
BEGINNING
Perl
Curtis “Ovid” Poe
John Wiley & Sons, Inc.
ffirs.indd vffirs.indd v 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
Beginning Perl
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
w w w.wile y.com
Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-118-01384-7
ISBN: 978-1-118-22187-7 (ebk)
ISBN: 978-1-118-23563-8 (ebk)
ISBN: 978-1-118-26051-7 (ebk)
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the

Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011,
fax (201) 748-6008, or online at http://w w w.wiley.com/go/per missions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and speci cally disclaim all warranties, including
without limitation warranties of  tness for a particular purpose. No warranty may be created or extended by sales or
promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is
sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional
services. If professional assistance is required, the services of a competent professional person should be sought. Neither
the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is
referred to in this work as a citation and/or a potential source of further information does not mean that the author or the
publisher endorses the information the organization or Web site may provide or recommendations it may make. Further,
readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this
work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with
standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media
such as a CD or DVD that is not included in the version you purchased, you may download this material at
. For more information about Wiley products, visit w w w.wiley.co m.
Library of Congress Control Number: 2012944681
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its af liates, in the United States and other
countries, and may not be used without written permission. All other trademarks are the property of their respective
owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book.
ffirs.indd viffirs.indd vi 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
This book is dedicated to my wife, Leïla, and our
daughter, Lilly-Rose.
When I  rst had the opportunity to write this book,
I was going to turn it down because I had a newborn

daughter. Leïla, however, insisted I write it. She
knows how much I love writing and was adamant that
she would be supportive while I wrote this book. She
has been more than supportive: She has kept me going
through a long, painful process. Leïla, I love you. And
beaucoup. You know what I mean.
ffirs.indd viiffirs.indd vii 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
Acquisitions Editor
Mary James
Project Editor
Maureen Spears
Technical Editor
chromatic
Production Editor
Christine Mugnolo
Copy Editor
San Dee Phillips
Editorial Manager
Mary Beth Wakefi eld
Freelancer Editorial Manager
Rosemarie Graham
Associate Director of Marketing
David Mayhew
Marketing Manager
Ashley Zurcher
Business Manager
Amy Knies
Production Manager
Tim Tate

Vice President and Executive Group
Publisher
Richard Swadley
Vice President and Executive Publisher
Neil Edde
Associate Publisher
Jim Minatel
Project Coordinator, Cover
Katie Crocker
Proofreader
James Saturnio, Word One New York
Indexer
Robert Swanson
Cover Designer
Ryan Sneed
Cover Image
© RTimages / iStockPhoto
CREDITS
ffirs.indd viiiffirs.indd viii 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
ABOUT THE AUTHOR
CURTIS “OVID” POE started programming back in 1982 and has been programming Perl almost
exclusively for 13 years. He currently sits on the Board of Directors for the Perl Foundation, speaks
at conferences in many countries, but is most proud of being a husband and father.
ABOUT THE TECHNICAL EDITOR
CHROMATIC is a proli c writer and developer. He is most recently the author of Modern Perl, from
Onyx Neon Press (
/>ffirs.indd ixffirs.indd ix 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
ffirs.indd xffirs.indd x 8/9/12 2:02 PM8/9/12 2:02 PM

www.it-ebooks.info
ACKNOWLEDGMENTS
AS WITH MANY BOOKS, this one would not have been possible without many people helping me
along the way. In particular, I want to thank Michael Rasmussen, my “secret reviewer” who, despite
not being one of the of cial reviewers, nonetheless diligently reviewed every chapter and came back
with many helpful comments that made this a far better book.
I also have to thank chromatic, my technical reviewer, who managed to annoy me time and time
again by pointing out subtle issues that I should have caught but didn’t. He’s a better programmer
than I am, damn it.
Mary James and Maureen Spears, my primary contacts at Wiley, Wrox imprint, were a joy to work
with and really helped keep my spirits up when this book seemed to drag on far longer than
I thought. Their senses of humor and help through the editorial process were invaluable. I also have
to thank San Dee, whoever the heck she is. Her name kept popping up through the editorial process
and her work catching many issues in this book is much appreciated.
I also need to thank Adrian Howard, Ævar Arnfjörð Bjarmason, Alejandro Lopez, Andy
Armstrong, Aristotle, Michael Schwern, Ricardo Signes, Sean T Lewis, and Simon Cozens for
foolishly agreeing to review a book of this length.
Finally, I’d like to thank the people working on the Open Feedback Publishing System at O’Reilly
and for engendering a review community (
for
this book and for all the helpful comments this site generated.
There are far too many to name and I apologize in advance for not mentioning all of you here.
On a personal note, I have to say that many times I’ve read the comment “and all errors are mine”
and I’ve thought, “But that’s what reviewers are for, right?” The reality is far different. When you
write a book, the reviewers will catch a huge number of issues, as mine did, but they can’t catch all
of them. I now realize that in a work of this scope, I have to take responsibility for any  aws. The
reviewers are generally not paid for this work and they’re not going to sit there, hours every night,
months on end, worrying over every paragraph as I did. They caught most issues, but the remaining
 aws in this work are mine and mine alone. Mea Culpa.
ffirs.indd xiffirs.indd xi 8/9/12 2:02 PM8/9/12 2:02 PM

www.it-ebooks.info
ffirs.indd xiiffirs.indd xii 8/9/12 2:02 PM8/9/12 2:02 PM
www.it-ebooks.info
CONTENTS
INTRODUCTION xxiii
CHAPTER 1: WHAT IS PERL? 1
Perl Today 2
Getting Perl 3
Working with Non-Windows Platforms: perlbrew 4
Using Windows 6
The Perl Community 8
IRC 8
PerlMonks 9
Perl Mongers 9
StackOverfl ow 9
Using perldoc 11
Understanding the Structure of perldoc 11
Getting Started with perldoc 11
Using Tutorials and FAQs 12
Using the perldoc -f function 14
Using a Terminal Window 14
Using the Command Line 15
Creating a Work Directory 16
Creating Hello, World! 18
Writing Your First Program 18
Shebang Lines 21
Summary 22
CHAPTER 2: UNDERSTANDING THE CPAN 25
CPAN and METACPAN 26
Finding and Evaluating Modules 27

Downloading and Installing 29
CPAN Clients 33
Using the CPAN.pm Client 33
Using the Cpanm Client 35
PPM 36
CPAN::Mini 36
Summary 39
ftoc.indd xiiiftoc.indd xiii 8/9/12 8:03 AM8/9/12 8:03 AM
www.it-ebooks.info
xiv
CONTENTS
CHAPTER 3: VARIABLES 41
What Is Programming? 42
A Few Things to Note Before Getting Started 43
strict, warnings, and diagnostics 43
The my Function 43
Sigils 44
Identifi ers 45
Scalars 46
Strings 47
Numbers 51
Arrays 53
Breaking Down the Code 54
Accessing Elements 55
Iterating over Arrays 58
Hashes 58
Accessing Elements 59
Iterating Over Hashes 60
Adding Data to Hashes 60
Slices 61

Array Slices 62
Hash Slices 62
Context 63
Scalar Context 63
List Context 64
Scope 67
my Variables 67
Package Variables 69
Strict, Warnings, and Diagnostics 72
strict 74
warnings 74
diagnostics 75
Working Without a Net 76
Perl’s Built-in Variables 78
$_ 78
%ENV 79
@ARGV 79
Other Special Variables 80
Summary 81
CHAPTER 4: WORKING WITH DATA 83
Using Scalars 84
Working with Strings 85
ftoc.indd xivftoc.indd xiv 8/9/12 8:03 AM8/9/12 8:03 AM
www.it-ebooks.info
xv
CONTENTS
Using String Operators 94
Scalar::Util 97
Numeric Builtins 98
Bitwise Operators 103

Understanding Booleans 103
Assignment Operators 108
Precedence and Associativity 109
Array and List Functions 111
Built-in Array Functions 111
List::Util 116
Built-in Hash Functions 116
delete() 116
exists() 117
keys() 117
values() 117
each() 117
Scoping Keywords 119
my() 119
local() 119
our() 120
state() 120
Summary 121
CHAPTER 5: CONTROL FLOW 125
Using the if Statement 126
Understanding Basic Conditionals 126
else/elsif/unless 128
The Ternary Operator ?: 131
for/foreach loops 132
Arrays 132
Lists 135
C-Style 136
Using while/until Loops 142
Lists 143
last/next/redo/continue 144

Labels 146
Statement Modifi ers 147
Types of Statement Modifi ers 147
do while/do until 149
given/when 151
Basic Syntax 151
The Switch Module 153
Summary 154
ftoc.indd xvftoc.indd xv 8/9/12 8:03 AM8/9/12 8:03 AM
www.it-ebooks.info
xvi
CONTENTS
CHAPTER 6: REFERENCES 157
References 101 158
Array References 158
Hash References 159
Anonymous References 160
Other References 163
Working with References 166
Debugging 166
Copying 169
Slices 172
Summary 173
CHAPTER 7: SUBROUTINES 175
Subroutine Syntax 176
Argument Handling 177
Multiple Arguments 178
Named Arguments 179
Aliasing 181
State Variables (Pre- and Post-5.10) 181

Passing a List, Hash, or Hashref? 184
Returning Data 186
Returning True/False 186
Returning Single and Multiple Values 188
wantarray 189
FAIL! 190
“Wake Up! Time to Die!” 191
carp and croak 192
eval 192
evalGotchas 194
Try::Tiny 195
Subroutine References 196
Existing Subroutines 196
Anonymous Subroutines 197
Closures 197
Prototypes 200
Argument Coercion 200
More Prototype Tricks 202
Mimicking Builtins 204
Forward Declarations 206
Prototype Summary 207
ftoc.indd xviftoc.indd xvi 8/9/12 8:03 AM8/9/12 8:03 AM
www.it-ebooks.info
xvii
CONTENTS
Recursion 209
Basic Recursion 209
Divide and Conquer 210
Memoization 211
Things to Watch For 215

Argument Aliasing 215
Scope Issues 216
Doing Too Much 216
Too Many Arguments 217
Summary 217
CHAPTER 8: REGULAR EXPRESSIONS 219
Basic Matching 220
Quantifi ers 221
Escape Sequences 223
Extracting Data 226
Modifi ers and Anchors 228
Character Classes 231
Grouping 232
Advanced Matching 235
Substitutions 235
Lookahead/Lookbehind Anchors 236
Named Subexpressions (5.10) 238
Common Regular Expression Issues 241
Regexp::Common 241
E-mail Addresses 242
HTML 242
Composing Regular Expressions 243
Summary 245
CHAPTER 9: FILES AND DIRECTORIES 249
Basic File Handling 250
Opening and Reading a File 250
File Test Operators 258
The Diamond Operator 260
Temporary Files 260
DATA as a File 261

binmode 262
Directories 265
Reading Directories 265
Globbing 265
ftoc.indd xviiftoc.indd xvii 8/9/12 8:03 AM8/9/12 8:03 AM
www.it-ebooks.info
xviii
CONTENTS
Unicode 266
What Is Unicode? 267
Two Simple Rules 267
Lots of Complicated Rules 271
Useful Modules 276
File::Find 276
File::Path 278
File::Find::Rule 279
Summary 284
CHAPTER 10: SORT, MAP, AND GREP 287
Basic Sorting 288
Sorting Alphabetically 288
Sorting Numerically 289
Reverse Sorting 290
Complex Sort Conditions 290
Writing a sort Subroutine 292
Sorting and Unicode Fun! 293
map and grep 297
Using grep 298
Using map 303
Aliasing Issues 305
Trying to Do Too Much 306

Trying to Be Clever 307
Putting It All Together 308
Schwartzian Transform (aka decorate, sort, undecorate) 308
Guttman-Rosler Transform 310
Summary 311
CHAPTER 11: PACKAGES AND MODULES 315
Namespaces and Packages 316
use Versus require 321
Package Variables 323
Version Numbers 326
Subroutines in Other Packages 327
Exporting 327
Naming Conventions 330
BEGIN, UNITCHECK, CHECK, INIT, and END 335
BEGIN blocks 336
END Blocks 337
ftoc.indd xviiiftoc.indd xviii 8/9/12 8:03 AM8/9/12 8:03 AM
www.it-ebooks.info
xix
CONTENTS
INIT, CHECK, and UNITCHECK Blocks 337
Plain Old Documentation (POD) 338
Documentation Structure 340
Headings 340
Paragraphs 341
Lists 341
Verbatim 342
Miscellaneous 342
Creating and Installing Modules 344
Creating a Simple Module 344

Makefi le.PL or Module::Build? 349
Summary 349
CHAPTER 12: OBJECT ORIENTED PERL 353
What Are Objects? The Ævar the Personal Shopper 354
Three Rules of Perl OO 355
Class Is a Package 355
An Object Is a Reference That Knows Its Class 356
A Method Is a Subroutine 358
Objects – Another View 371
Using TV::Episode 371
Subclassing 374
Using TV::Episode::Broadcast 375
Class Versus Instance Data 379
A Brief Recap 381
Overloading Objects 381
Using UNIVERSAL 385
Understanding Private Methods 387
Gotchas 393
Unnecessary Methods 393
“Reaching Inside” 394
Multiple Inheritance 394
Summary 397
CHAPTER 13: MOOSE 399
Understanding Basic Moose Syntax 400
Using Attributes 402
Using Constructors 405
Understanding Inheritance 408
Taking Care of Your Moose 409
ftoc.indd xixftoc.indd xix 8/9/12 8:03 AM8/9/12 8:03 AM
www.it-ebooks.info

xx
CONTENTS
Advanced Moose Syntax 413
Using Type Constraints 414
Using Method Modifi ers 417
Understanding and Using Roles 420
Exploring MooseX 425
Rewriting Television::Episode 428
Moose Best Practices 433
Use namespace::autoclean and Make Your Class Immutable 434
Never Override new() 434
Always Call Your Parent BUILDARGS Method 434
Provide Defaults if an Attribute is Not Required 434
Default to Read-Only 434
Put Your Custom Types in One Module and
Give Them a Namespace 435
Don’t Use Multiple Inheritance 435
Always Consume All Your Roles at Once 435
Summary 436
CHAPTER 14: TESTING 439
Basic Tests 440
Using Test::More 440
Writing Your Tests 442
Understanding the prove Utility 443
Understanding Test::More Test Functions 444
Using ok 445
Using is 445
Using like 448
Using is_deeply 449
Using SKIP 450

Using TODO 450
Using eval {} 451
Using use_ok and require_ok 452
Working with Miscellaneous Test Functions 453
Using Other Testing Modules 457
Using Test::Di erences 457
Using Test::Exception 459
Using Test::Warn 460
Using Test::Most 460
Understanding xUnit Style Using Testing 461
Using Test::Class 461
A Basic Test Class 463
Extending a Test Class 467
ftoc.indd xxftoc.indd xx 8/9/12 8:03 AM8/9/12 8:03 AM
www.it-ebooks.info
xxi
CONTENTS
Using Test Control Methods 471
Calling Parent Test Control Methods 473
Summary 477
CHAPTER 15: THE INTERWEBS 481
A Brief Introduction to HTTP 482
Plack 484
Hello, World! 484
Handling Parameters 490
Templates 492
Handling POST Requests 496
Sessions 500
Web Clients 511
Extracting Links from Web Pages 512

Extracting Comments from Web Pages 514
Filling Out Forms Programmatically 515
Summary 520
CHAPTER 16: DATABASES 523
Using the DBI 524
Connecting to a Database 524
Using SQLite 527
Using DBD::SQLite 527
Selecting Basic Data 533
Using SELECT Statements 533
Using Bind Parameters 536
Inserting and Updating Data 539
Creating Transactions 540
Handling Errors 541
Summary 542
CHAPTER 17: PLAYS WELL WITH OTHERS 545
The Command Line 546
Reading User Input 546
Handling Command-Line Arguments 548
perlrun 551
Other Programs 556
Running an External Program 556
Reading Another Program’s Output 559
Writing to Another Program’s Input 560
STDERR 562
Summary 565
ftoc.indd xxiftoc.indd xxi 8/9/12 8:03 AM8/9/12 8:03 AM
www.it-ebooks.info
xxii
CONTENTS

CHAPTER 18: COMMON TASKS 567
Using CSV Data 568
Reading CSV Data 569
Writing CSV Data 570
Understanding Basic XML 571
Reading CSV Data 572
Writing CSV Data 576
Handling Dates 580
Using the DateTime Module 580
Using Date::Tiny and DateTime::Tiny 581
Understanding Your Program 587
Using the Debugger 587
Profi ling 594
Perl::Critic 604
Summary 608
CHAPTER 19: THE NEXT STEPS 611
What Next? 612
What This Book Covers 612
What This Book Leaves Out 613
Understanding Object-Relational Mappers 613
Understanding DBIx::Class 614
Understanding Basic DBIx::Class Usage 614
Understanding the Pros and Cons of an ORM 618
Using DBIx::Class::Schema::Loader 624
Using the Template Toolkit 625
Why Use Templates? 625
An Introduction to Template Toolkit 626
Using Catalyst to Build Apps 634
The Beauty of MVC 635
Setting Up a Catalyst Application 635

Using Catalyst Views 641
Using Catalyst Models 643
Using Catalyst Controllers 646
CRUD: Create, Read, Update, and Delete 648
Summary 651
APPENDIX: ANSWERS TO EXERCISES 655
INDEX 695
ftoc.indd xxiiftoc.indd xxii 8/9/12 8:03 AM8/9/12 8:03 AM
www.it-ebooks.info
INTRODUCTION
“Get a job, hippy!”
That was the subtitle for this book that was sadly, but wisely, rejected. However, it conveys two
things about this book that I’ve tried to focus on: getting a job and having fun while learning the
skills you need. Well, as much fun as you can reasonably have while learning how to program.
Although many books aren’t explicit in this intent, I’ll say it up front: This book is about money.
Information Technology (IT) workers are in high demand, even during the current economic down-
turn, and this book draws not only on your author’s 13 years of experience with the Perl program-
ming language, but also on surveys that have been conducted regarding “Perl in the wild.” That’s
why you’ll  nd an astonishing decision in this book: We focus on Perl versions 5.8 and 5.10. They’re
no longer of cially supported, but these are the versions of Perl that most companies still use.
Fortunately, the Perl 5 Porters (also known as P5P) strive hard to maintain backward compatibility,
so the code in this book still runs on the latest versions of Perl. As a result of this focus, by the time
you  nish this book, you’ll have the skills necessary to accept many Perl jobs.
I  rst conceived of a Perl book aimed at developing job skills when I was living in Portland, Oregon.
Later, I moved to London and made a few inquiries about working on it, but to no avail. Then I
moved to Amsterdam and started working with Wrox to create this book. I’m now living in Paris
and am  nishing this book. The common thread in all those cities is that Perl opened up the door
for jobs. With many other excellent dynamic programming languages, such as PHP, Python, and
Ruby  ghting for the same slice of the pie, some Perl developers moved to other languages, leaving
companies in need of developers to maintain their code and build new systems in Perl. Perl develop-

ers are in high demand, and this book is about meeting that demand.
Lest you think that Perl is just for maintaining legacy code, I can assure you that plenty of com-
panies, large and small, are still turning to Perl as their  rst choice of programming language. It’s
powerful, solid, and the Comprehensive Perl Archive Network (CPAN) is still the largest collection
of open source code dedicated to a single language. Many times you’ll  nd that rather than need-
ing to write new code to solve a tricky problem, you can turn to the CPAN and  nd that someone’s
already written that code.
I’ve been paid to program in many languages, including 6809 Assembler (boy, did I just date myself,
or what?), BASIC, C, Java, COBOL, FOCUS, JCL (Job Control Language), VBA, and JavaScript,
but I keep coming back to Perl. Why? Well, why not? It’s a powerful language. If your programming
needs are CPU-bound, such as in real-time ray tracing, then Perl may not be the best choice, but oth-
erwise, it’s an excellent language. I tend to work on large-scale database-driven applications, and the
performance issues there are usually located in the network, the database, or the  le system. You’d
have the same performance issues regardless of the programming language, so you may as well
choose a language that you enjoy.
flast.indd xxiiiflast.indd xxiii 8/9/12 8:08 AM8/9/12 8:08 AM
www.it-ebooks.info

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×