9780672327933

Sams Teach Yourself Perl in 24 Hours

by
  • ISBN13:

    9780672327933

  • ISBN10:

    0672327937

  • Edition: 3rd
  • Format: Paperback
  • Copyright: 2005-06-15
  • Publisher: Sams Publishing
  • Purchase Benefits
  • Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $34.99 Save up to $5.25
  • Buy New
    $29.74

    CURRENTLY AVAILABLE, USUALLY SHIPS IN 24-48 HOURS

Supplemental Materials

What is included with this book?

  • The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

Summary

Learn Perl programming quickly and easily with 24 1-hour lessons, including new uses of Perl and a look ahead to Perl 6.

Author Biography

Sams Teach Yourself Perl in 24 Hours, Third Edition About the Author

Clinton Pierce is a software engineer, freelance programmer, and instructor. He has been answering questions about Perl on USENET for many years and has been writing courseware and teaching Perl to his co-workers and anyone else who will listen for about as long. He is a software engineer for a payroll company, who, when not designing middleware software to integrate legacy systems to the Web, navigating the intricacies of payroll taxes, teaching UNIX and Perl, writing books and articles, or writing programs at home Just For The Fun Of It, harbors secret dreams of being abducted by wood nymphs and living in the deep forest without technology. You can visit his Web site at http://www.geeksalad.org for updates and corrections, or just to say hello.


© Copyright Pearson Education. All rights reserved.

Table of Contents

Introduction 1(1)
How to Use This Book 1(1)
Conventions Used in This Book 2(3)
Part I: Perl Fundamentals
Getting Started with Perl
5(16)
Installing Perl
6(5)
Stop! Wait! Maybe You Already Have Perl
6(2)
Installing Perl on Windows
8(1)
Installing Perl on Unix
9(1)
Installing Perl on Mac OS
10(1)
Documentation
11(3)
Some Special Documentation Cases
12(1)
What If You Can't Find the Documentation?
13(1)
Your First Program
14(7)
Typing Your First Program
14(1)
Running the Program
15(1)
It Worked! So What Happened?
16(1)
Perl Play-by-Play
17(1)
Something You Should Know
17(4)
Perl's Building Blocks: Numbers and Strings
21(18)
Literals
22(3)
Numbers
22(1)
Strings
23(2)
Scalar Variables
25(2)
The Special Variable $_
26(1)
Expressions and Operators
27(3)
Basic Operators
28(1)
Numeric Operators
28(1)
String Operators
29(1)
More Operators
30(5)
One-Operand (Unary) Operators
31(1)
Increment and Decrement
32(1)
Angle Operator (<>)
33(1)
More Assignment Operators
33(1)
A Few Words on Strings and Numbers
34(1)
Exercise: Interest Calculator
35(4)
Controlling the Program's Flow
39(20)
Blocks
40(1)
The if Statement
41(7)
The Other Relational Operators
42(2)
What Truth Means to Perl
44(2)
Logical Operators
46(2)
Looping
48(2)
Looping with while
48(1)
Looping with for
49(1)
Other Flow Control Tools
50(3)
Odd Arrangements
50(1)
Fine-Grained Control
51(1)
Labels
52(1)
Leaving Perl
53(1)
Exercise: Finding Primes
53(6)
Stacking Building Blocks: Lists and Arrays
59(22)
Putting Things into Lists and Arrays
60(3)
Arrays
61(2)
Getting Elements Out of an Array
63(6)
Finding the End of an Array
64(1)
Learning More about Context
65(1)
More about the Size and End of an Array
66(1)
Context with Operators and Functions
66(3)
Manipulating Arrays
69(5)
Stepping Through an Array
69(1)
Converting Between Arrays and Scalars
70(2)
Reordering Your Array
72(2)
Exercise: Playing a Little Game
74(7)
Working with Files
81(16)
Opening Files
81(5)
Pathnames
83(1)
A Good Defense
84(1)
dieing Gracefully
85(1)
Reading
86(3)
Writing
89(2)
Free Files, Testing Files, and Binary Data
91(6)
Free Filehandles
91(1)
Text Files and Binary Files
92(1)
File Test Operators
93(4)
Pattern Matching
97(20)
Simple Patterns
98(2)
Rules of the Game
99(1)
The Metacharacters
100(6)
A Simple Metacharacter
100(1)
The Unprintables
100(1)
Quantifiers
101(2)
Character Classes
103(1)
Grouping and Alternation
104(1)
Anchors
105(1)
Substitution
106(1)
Exercise: Cleaning Up Input Data
107(1)
Pattern Matching Odds and Ends
108(9)
Working with Other Variables
108(1)
Modifiers and Multiple Matching
109(1)
Backreferences
110(1)
A New Function: grep
111(6)
Hashes
117(18)
Filling Your Hash
118(1)
Getting Data Out of a Hash
119(2)
Lists and Hashes
121(1)
Hash Odds and Ends
122(2)
Testing for Keys in a Hash
123(1)
Removing Keys from a Hash
123(1)
Useful Things to Do with a Hash
124(3)
Determining Frequency Distributions
124(1)
Finding Unique Elements in Arrays
124(1)
Computing the Intersection and Difference of Arrays
125(2)
Sorting Hashes
127(1)
Exercise: Creating a Simple Customer Database with Perl
127(8)
Functions
135(20)
Creating and Calling Subroutines
135(5)
Returning Values from Subroutines
137(1)
Arguments
138(1)
Passing Arrays and Hashes
139(1)
Scope
140(3)
Other Places for my
142(1)
Exercise: Statistics
143(2)
Function Footnotes
145(10)
Declaring Variables local
146(1)
Making a Stricter Perl
147(1)
Recursion
148(7)
Part II: Advanced Features
More Functions and Operators
155(16)
Searching Scalars
155(3)
Searching with index
156(1)
Searching Backward with rindex
157(1)
Picking Apart Scalars with substr
157(1)
Transliteration, Not Substitution
158(1)
A Better Way to print
159(3)
Formatted Printing with printf
159(1)
Specifying the Field Formats
160(2)
Formatted Output to a String
162(1)
Exercise: A Formatted Report
162(2)
New Ways with Arrays
164(7)
A List as a Stack
164(3)
Splicing Arrays
167(4)
Files and Directories
171(18)
Getting a Directory Listing
172(3)
Globbing
173(2)
Exercise: The Unix grep
175(2)
Directories
177(4)
Navigating Directories
177(1)
Creating and Removing Directories
178(1)
Removing Files
179(1)
Renaming Files
180(1)
Unix Stuff
181(2)
A Crash Course in File Permissions
181(2)
Everything You Ever Wanted to Know About That File
183(2)
Exercise: Renaming Files En Masse
185(4)
System Interaction
189(16)
The system() Function
190(2)
The Underlying Command Interpreter
191(1)
Capturing Output
192(2)
Avoiding Your Shell
193(1)
Pipes
194(3)
First Lesson in Portability
197(8)
Telling the Difference: An Example
198(7)
Using Perl's Command-Line Tools
205(14)
What Is the Debugger?
205(7)
Starting the Debugger
206(1)
Basic Debugger Commands
207(1)
Breakpoints
208(2)
Other Debugger Commands
210(2)
Exercise: Finding the Bug
212(1)
Other Command-Line Stuff
212(7)
One-Liners
213(1)
Other Switches
214(1)
Empty Angle Brackets and More One-Liners
215(4)
References and Structures
219(18)
Reference Basics
220(7)
References to Arrays
222(1)
References to Hashes
223(1)
References as Arguments
223(2)
Building Structures
225(2)
Recipes for Structures
227(3)
Example: A List of Lists
227(1)
Other Structures
228(1)
Debugging with References
229(1)
Exercise: Another Game, Maze
230(7)
Using Modules
237(16)
A Gentle Introduction
238(3)
Reading the Documentation
239(1)
What Can Go Wrong?
240(1)
A Quick Tour
241(6)
Exploring Files and Directories
241(3)
Copying Files
244(1)
Is Anybody Out There?
245(1)
Once Again, in English?
246(1)
More Diagnostics
246(1)
Full List of Standard Modules
247(6)
Where Do You Go from Here?
249(4)
Finding Permanence
253(20)
DBM Files
253(3)
Important Points to Know
255(1)
Walking Through DBM-Tied Hashes
255(1)
Exercise: A Free-Form Memo Pad
256(3)
Text Files as Databases
259(3)
Inserting into or Removing from a Text File
260(2)
Random File Access
262(2)
Opening Files for Read and Write
262(1)
Moving Around in a Read/Write File
263(1)
Locking
264(9)
Locking with Unix and Windows
265(3)
Reading and Writing with a Lock
268(1)
Locking with Windows 95 and Windows 98
269(1)
Locking Elsewhere
269(4)
The Perl Community
273(18)
What's Perl All About, Anyway?
273(4)
A Brief History of Perl
273(2)
Open Source
275(1)
The Development of Perl
276(1)
The Comprehensive Perl Archive Network (CPAN)
277(2)
What Is CPAN?
277(1)
Why Do People Contribute?
278(1)
Your Next Steps
279(7)
Your First Step
279(1)
Your Most Useful Tool
280(1)
Debug Your Program
280(1)
First, Help Yourself
281(1)
Learn from the Mistakes of Others
282(1)
When All Else Fails, Ask
283(2)
Another Place to Look and Ask: PerlMonks
285(1)
Other Resources
286(5)
Part III: Applying Perl
Writing Modules
291(14)
Building a Module
292(2)
Calling the Module
293(1)
Namespaces
293(1)
Scoping Revisited
294(1)
Another statement: our
295(3)
Forcing Your Names on Others
296(2)
Example: A Module to Handle Common File Information Requests
298(7)
Object Primer
305(14)
Classes, Properties, and Methods
306(1)
A Thought-class: Car
306(1)
Example: Implementation of Car in Perl
307(5)
Using the Car Class
310(2)
Example: File Information Class
312(7)
Using the File Information Class
314(5)
Data Processing
319(18)
How to Look at Data
320(2)
Unstructured Data
320(1)
Table Data
321(1)
Hierarchical Data
321(1)
Binary Data
321(1)
Dealing with Table Data
322(5)
Example: Email Order Taker
323(2)
Example: Verifier for the Email Order
325(2)
XML Data
327(10)
Reading XML Using Regular Expressions
328(3)
Reading XML with XML::Simple
331(1)
Example: Extending Your Ordering System for XML Input
332(5)
Perl as a Glue Language
337(20)
Weather Station
337(7)
Part 1: Finding Out Where You Are
339(2)
Part 2: Finding the Local Airport
341(2)
Part 3: Fetching the Weather and Putting It All Together
343(1)
Presenting Data as PDF
344(5)
Example: Weather Report as PDF
346(3)
Reading and Writing Excel Spreadsheets
349(8)
Using Perl to Create a Spreadsheet
350(2)
Reading the Spreadsheet
352(5)
Introduction to CGI
357(16)
Browsing the Web
358(3)
Fetching a Static Web Page
358(2)
Dynamic Web Content---The CGI
360(1)
Don't Skip This Section
361(2)
The Checklist
362(1)
Your First CGI Program
363(3)
Installing the CGI Program on the Server
364(2)
Running Your CGI Program
366(1)
What to Do When Your CGI Program Doesn't Work
366(7)
Is It Your CGI Program?
367(1)
Server Problems
368(1)
Fixing Internal Server or 500 Errors
369(4)
Basic Forms
373(16)
How Forms Work
373(3)
Short Review of HTML Form Elements
373(2)
What Happens When You Click Submit?
375(1)
Passing Information to Your CGI Program
376(2)
GET and POST Methods
377(1)
Web Security 101
378(5)
A Clear Link
379(1)
Watching for Insecure Data
380(2)
Doing the Impossible
382(1)
Denial of Service
382(1)
A Guestbook
383(6)
Complex Forms
389(14)
The Stateless Web
389(1)
Hidden Fields
390(2)
The Online Store
390(2)
A Multipage Survey
392(11)
Manipulating HTTP and Cookies
403(22)
The HTTP Conversation
403(4)
Example: Fetching a Page Manually
405(1)
Redirection
406(1)
More Details on Calling CGI Programs
407(3)
Passing Parameters to CGI Programs
408(1)
Special Parameter Considerations
409(1)
Cookies
410(6)
How to Make Cookies
412(1)
Example: Using Cookies
413(2)
Restricting Cookies
415(1)
Long Term Cookies
416(2)
Problems with Cookies
418(7)
Cookies Are Ephemeral
418(1)
Cookies Aren't Always Supported
418(1)
Some People Don't Like Cookies
418(7)
Part IV: Appendixes
APPENDIX A: Installing Modules
425(8)
Picking the Right Module
425(1)
Installing the Modules Under...
425(5)
...Windows
426(1)
...Unix, Using CPAN
427(2)
...Unix, The Hard Way
429(1)
...Mac OS X
430(1)
What to Do When You're Not Allowed to Install Modules
430(3)
Using Modules Installed in Strange Places
431(2)
Index 433

Excerpts

= 0) {slash = '\\';} else {slash = '/';}openLoc = figLoc.substring(0, figLoc.lastIndexOf(slash) + 1);while (pPage.substring(0,3) == '../') {openLoc = openLoc.substring(0, openLoc.lastIndexOf(slash, openLoc.length - 2)+ 1);pPage = pPage.substring(3, pPage.length + 1);}popUpWin =window.open('','popWin','resizable=1,scrollbars=1,location=0,toolbar=0,width=525,height=394');figDoc = popUpWin.document;zhtm= ' ' + pPage + ' ';zhtm += ' ';zhtm += ' ';zhtm += ' ';zhtm += '' + pPage.substring(pPage.lastIndexOf('/') + 1, pPage.length) + '';zhtm += ' ';figDoc.write(zhtm);figDoc.close();}// modified 3.1.99 RWE v4.1 --> Introduction Introduction"Any sufficiently advanced technology is virtually indistinguishable from magic." --Arthur C. ClarkeRemember this well:There's nothing magical about programming a computer.Like anything that seems magical, there's always a trick to it--and programming is no different. All you need are some analytical thinking skills, the desire to learn, and some time to learn Perl. The best way to learn how to program a computer--or any task really--is to have a goal. Your goal could be to spice up your Web pages, convert a program you already have to Perl, or to satisfy idle curiosity--it doesn't really matter.Now, given that you've established a goal and have some thinking skills, what does this book have for you?This book will teach you the basics of the Perl programming language. You'll learn just enough Perl to do something useful. You will not be overwhelmed with details that, although interesting, will only get in your way and that you'll probably never use again. Each new concept in this book is demonstrated by lots of working code examples. Go ahead--flip through the book and see.But why Perl? Almost every company that uses programming of some kind uses Perl. Perl is found in finance, manufacturing, genetics, the military, and every other application known to humankind. And, of course, Perl is used on the Internet and the World Wide Web. Perl isn't going away any time soon, which is why learning it is an investment in your time that will pay off for years to come.It's also possible to create really stunning Perl programs with just a small bit of code. Using a little bit of Perl to glue together other applications, languages, and technologies, you'll be creating useful Perl programs in no time. How to Use This BookThis book is divided into 24 segments that take roughly an hour to complete. You can work through the lessons in the space of a day (if you don't plan to eat or sleep), or you can ta

Rewards Program

Write a Review