Beginning Perl
Wrox Press (Verlag)
978-1-118-01384-7 (ISBN)
Everything beginners need to start programming with Perl Perl is the ever-popular, flexible, open source programming language that has been called the programmers’ Swiss army knife. This book introduces Perl to both new programmers and experienced ones who are looking to learn a new language. In the tradition of the popular Wrox Beginning guides, it presents step-by-step guidance in getting started, a host of try-it-out exercises, real-world examples, and everything necessary for a Perl novice to start programming with confidence.
Introduces Perl to both new programmers and experienced ones who want to learn a new language
Provides a host of real-world applications for today's environments so readers can get started immediately
Covers the new features of Perl but fully applicable to previous editions
Beginning Perl provides the information and instruction you need to confidently get started with Perl.
For Instructors: Classroom and training support material are available for this book.
Curtis "Ovid" Poe has specialized in Perl since 2000. He is an author, a regular guest speaker at conferences across Europe and the United States, and he wrote the test harness that currently ships with the Perl language. "This is not your everyday Beginning Perl book. Not only does Ovid provide splendid coverage of Perl's basics and best practices, he also covers modern Perl techniques and modules, where Perl's real power lies. [It] is like being given Batman's utility belt: you have everything you need to do truly amazing things. If Perl were a shark, this book would teach you how to outfit it with lasers." Paul Fenwick, Perl Training Australia Wrox Beginning guides are crafted to make learning programming languages and technologies easier than you think, providing a structured, tutorial format that will guide you through all the techniques involved.
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
StackOverflow 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
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
Identifiers 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
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 Modifiers 147
Types of Statement Modifiers 147
do while/do until 149
given/when 151
Basic Syntax 151
The Switch Module 153
Summary 154
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
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
Quantifiers 221
Escape Sequences 223
Extracting Data 226
Modifiers 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
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
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
Advanced Moose Syntax 413
Using Type Constraints 414
Using Method Modifiers 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::Diff 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
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
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
Erscheint lt. Verlag | 14.9.2012 |
---|---|
Sprache | englisch |
Maße | 188 x 236 mm |
Gewicht | 1238 g |
Themenwelt | Informatik ► Programmiersprachen / -werkzeuge ► Perl |
ISBN-10 | 1-118-01384-0 / 1118013840 |
ISBN-13 | 978-1-118-01384-7 / 9781118013847 |
Zustand | Neuware |
Informationen gemäß Produktsicherheitsverordnung (GPSR) | |
Haben Sie eine Frage zum Produkt? |
aus dem Bereich