new able of ontents i using perl 1ptgmedia.pearsoncmg.com/images/073571228x/toc/073571228... ·...

4
T ABLE OF CONTENTS I Using Perl 1 1 Exploring Perl 3 Online Documentation 4 CPAN (The Module Archive) 8 Installing Modules 11 Using the Perl Debugger 28 Summary 32 Exercises 32 Resources 33 2 Perl Basics 35 Writing Your First Perl Program 35 Variable Declarations and Simple Expressions 37 Reading Input 41 The if Statement and Relational Operators 42 The Definition of Truth 46 Looping Statements 48 Simple I/O 49 Summary 51 Exercises 52 Resources 52 3 Arrays 53 Basic Arrays 53 Manipulating the Array Ends 57 The splice Function 61 The split and join Functions 64 Sorting an Array 67 Multiple Dimension Arrays 67 The @ARGV Variable 68 The English Module 68 Summary 68 Exercises 68 Resources 70 4 Regular Expressions 71 Basic Regular Expressions 71 Substitutions 94 The grep Function 95 Summary 95 Exercises 96 Resources 98

Upload: others

Post on 17-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: New ABLE OF ONTENTS I Using Perl 1ptgmedia.pearsoncmg.com/images/073571228x/toc/073571228... · 2009. 6. 9. · 5 Perl’s New Syntax 101 New and Useful Syntax 101 Perl’s Darker

TABLE OF CONTENTS

I Using Perl 11 Exploring Perl 3

Online Documentation 4CPAN (The Module Archive) 8Installing Modules 11Using the Perl Debugger 28Summary 32Exercises 32Resources 33

2 Perl Basics 35Writing Your First Perl Program 35Variable Declarations and SimpleExpressions 37Reading Input 41The if Statement and Relational Operators 42The Definition of Truth 46Looping Statements 48Simple I/O 49Summary 51Exercises 52Resources 52

3 Arrays 53Basic Arrays 53Manipulating the Array Ends 57The splice Function 61The split and join Functions 64Sorting an Array 67Multiple Dimension Arrays 67The @ARGVVariable 68The English Module 68Summary 68Exercises 68Resources 70

4 Regular Expressions 71Basic Regular Expressions 71Substitutions 94The grep Function 95Summary 95Exercises 96Resources 98

00 228x_FM 7/11/02 3:47 PM Page vi

Page 2: New ABLE OF ONTENTS I Using Perl 1ptgmedia.pearsoncmg.com/images/073571228x/toc/073571228... · 2009. 6. 9. · 5 Perl’s New Syntax 101 New and Useful Syntax 101 Perl’s Darker

5 Perl’s New Syntax 101New and Useful Syntax 101Perl’s Darker Corners 109Summary 110Exercises 111Resources 111

6 Hashes, References, and Complex Data Structures 113Hashes 113References 121Translating C Data Structures into Perl 123Summary 128Exercises 128Resources 129

7 Subroutines and Modules 131Subroutines 131Packages 137Summary 144Exercises 145Resources 145

8 Object-Oriented Programming 147Using a Hash as an Object 147Basic Perl Objects 151Operator Overloading 154Summary 159Exercises 159Resources 160

9 Advanced I/O 161Opening a File (Revisited) 161sysopen (Advanced open) 163Reading a Binary File 164File Handling Package 167Passing a File Handle to a Subroutine 167References to a File Handle 168Summary 168Exercises 168Resources 169

10 POD 171POD (Plain Old Documentation) 171Turning POD into Something Readable 177Putting a --help Option in Your Files 177The POD Template 178Summary 180Exercise 181Resources 181

viiContents

00 228x_FM 7/11/02 3:47 PM Page vii

Page 3: New ABLE OF ONTENTS I Using Perl 1ptgmedia.pearsoncmg.com/images/073571228x/toc/073571228... · 2009. 6. 9. · 5 Perl’s New Syntax 101 New and Useful Syntax 101 Perl’s Darker

11 Under the Hood 183What Really Goes on When You Use Perl 183The Exporter Package 186How import and AUTOLOAD Work 186Summary 186Resources 187

12 CGI Programming 189Simple CGI 189CGI Hello World 190Basic Forms 193Creating the CGI Program 198Debugging a CGI Script 203Security 207Cookies 209Summary 210Exercises 210Resources 211

13 Creating GUIs with Tk 213Tk Basics 213Tk Widgets 214Geometry Managers 217Special Widgets 220Events 222General Design Hints 223Putting It All Together 223Summary 230Exercises 230Resources 231

14 Combining C and Perl with Inline::C 233What Is the Inline Module? 233Hello World 234Simple Arguments and Return Values 235How Perl Handles Variables 238Returning Multiple Values 241Calling Perl from C 244Configuring Inline 245Making a Distributable Module 245Summary 245Exercises 246Resources 246

15 Putting It All Together 249Perl and Databases 249Database Design 252Database Implementation 253The disk.pm Module 254GUI Interface 267

viii Contents

00 228x_FM 7/11/02 3:47 PM Page viii

Page 4: New ABLE OF ONTENTS I Using Perl 1ptgmedia.pearsoncmg.com/images/073571228x/toc/073571228... · 2009. 6. 9. · 5 Perl’s New Syntax 101 New and Useful Syntax 101 Perl’s Darker

The CGI Version 278Summary 291Exercises 291Resources 291

16 Cookbook 293List Differences 293Call 1-800-Confuse-Me 296Time Adjustment 299Calendar Programs 302Duplicate File Checker 307Table Formatting 311Log File Viewer 314Web Site Checker 326Object File Cross-Reference System 332Counting Web Page Hits 339Summary 352Exercises: 353Resources 353

17 Creating Modules 355The Module Creation Process 355Module Creation Cookbook 362Debugging a Module 366Summary 370Exercises 370Resources 371

II Appendixes 373A Installing Perl 375

Installing Perl on Linux 375Installing Perl on UNIX or Linux from Source Code 376Installing Perl on Microsoft Windows 381

B Turning Perl Scripts into Commands 383The UNIX/Linux Magic String 383Using the env Program 384The Shell Script Method 385Microsoft Windows .bat File 386Resources 388

C Beyond Perl 389Databases 389Tools for C/C++ Programmers 390Resources 396

Index 397

ixContents

00 228x_FM 7/11/02 3:47 PM Page ix