Tell Us What You Think!

As the reader of this book, you are our most important critic and commentator. We value your opinion and want to know what we're doing right, what we could do better, what areas you'd like to see us publish in, and any other words of wisdom you're willing to pass our way.

I welcome your comments. You can e-mail or write me directly to let me know what you did or didn't like about this book—as well as what we can do to make our books stronger.

Please note that I cannot help you with technical problems related to the topic of this book, and that due to the high volume of mail I receive, I might not be able to reply to every message.

When you write, please be sure to include this book's title and author as well as your name and phone or fax number. I will carefully review your comments and share them with the author and editors who worked on the book.

E-Mail: [email protected]
Mail: Mark Taber
Associate Publisher
Sams Publishing
201 West 103rd Street
Indianapolis,IN 46290 USA

Introduction

A long time ago at a workstation manufacturer far, far away, a young writer was learning how to program sed and awk scripts on Unix systems. This was before there was a Sams Teach Yourself Unix, so I learned Unix scripting the old-fashioned, time-honored way: trial and error, sketchy online documentation, copying other people's scripts, and asking a lot of questions. Particularly asking a lot of questions. Each time I got stuck I would send e-mail to my various Unix-proficient friends, and each time I would get a patient reply carefully pointing out what I was doing wrong. In addition to the advice, however, nearly every e-mail started with “You should use Perl to do that.”

It seemed that no matter what I wanted to do, the answer always included “you should use Perl to do that.” Eventually, I got the hint, abandoned the hodgepodge of Unix programs I was working with, and learned Perl. And now I can't imagine using anything else.

“You should use Perl to do that” could easily be the motto of the Perl language (except that it already has a number of mottoes). Perl is the duct tape of programmer tools; it might not be the best solution to any particular problem, but it's certainly capable and pretty darn useful for just about any problem. Quick to use, quick to run, quick to change, you can often hack together a solution to a problem in Perl faster than it would take a C++ IDE to start up.

And you accomplish these solutions not just on a Unix system—Perl runs on a wide variety of platforms including Windows and Mac, and is just as useful on those GUI-centric platforms as it is on a more command line–centric system such as Unix. Use the Web? Perl is one of the most popular languages (and arguably the standard) for writing CGI scripts and for maintaining Web servers.

However, before you can use Perl, you have to learn it. Perl is a mishmash of various Unix tools, shell scripting, C, and occasional object-oriented features. That's where Sams Teach Yourself Perl in 21 Days comes in. This book is a gentle but thorough introduction to the Perl language and how it can be used. If you're a beginning programmer, or if you have some background, you'll learn the basics and build on them as the book progresses. If you're an experienced programmer, you might find the first few chapters easy going, but there's plenty of content later to challenge even a veteran. In either case, by the time you finish this book you will have a near-complete grasp of the entirety of the Perl language and how to use it.

How This Book Is Organized

This book is split into 21 lessons and three weeks. Each week covers a variety of topics, growing in complexity, and building on the lessons before it.

Each lesson describes a topic and contains two or three examples that illustrate each topic. At the end of each lesson, you get a chance to apply what you've learned with quizzes and exercises (and the answers to those quizzes also appear at the end of each lesson). On the final day of each week, we'll pause for a day to explore some longer, more useful examples in Perl, to review what you've learned in the previous week and show how larger scripts can be built.

The lessons in Sams Teach Yourself Perl in 21 Days include the following:

Day 1, “An Introduction to Perl,” is the basic background to what Perl is, what it does, how it works, and how to get started using it.

Day 2, “Working with Strings and Numbers (Scalar Data),” introduces scalar data, the basic building blocks in the language, and some simple operators for using them.

Day 3, “More Scalar Data and Operators,” finishes up what we started on Day 2, with more detail on the various ways you can manipulate numbers and strings. You'll also get a basic introduction to input and output in this lesson.

Day 4, “Working with Lists and Arrays,” shows how to create and manipulate groups of data.

Day 5, “Working with Hashes,” expands on the information from the last lesson with an exploration of hashes (also called associative arrays or keyed lists).

Day 6, “Conditionals and Loops,” moves from the subject of data to program flow. This chapter covers conditionals (if statements) and loops (while and for) as well as similar constructs.

Day 7, “Exploring a Few Longer Examples,” is the first of our longer-example lessons. Here, we'll look at three examples that make use of what you've learned so far.

Day 8, “Manipulating Lists and Strings,” explores some of the various ways in which Perl can be used to manipulate data stored in either a list (an array or hash) or in a string. This includes searching, sorting, extracting, or adding elements, or processing all the elements in some way.

Day 9, “Pattern Matching with Regular Expressions,” is the first of two chapters exploring one of Perl's most powerful features, regular expressions, which allow you to create and match patterns of characters in data.

Day 10, “Doing More with Regular Expressions,” expands on what you learned the day before with more detail about extracting and replacing data matched by patterns, as well as building more complex patterns.

Day 11, “Creating and Using Subroutines,” delves into creating subroutines (sometimes called functions or procedures) to allow reusable code.

Chapter 12, “Debugging Perl,” is a bit of a sideline from the description of the core language. In this chapter we'll look at the source-level debugger that can help you track down subtle problems in your code.

Chapter 13, “Scope, Modules, and Importing Code,” collects several issues surrounding global and local variables, compile-time versus runtime execution, and the use of code libraries, called modules.

Chapter 14, “Exploring a Few Longer Examples,” is the second of the longer example chapters.

Day 15, “Working with Files and I/O,” expands on the simple input and output you've learned in the previous parts of the book. You explore working more directly with files on the computer's file system and doing more with getting input into a script and outputting data from that script.

Day 16, “Using Perl for CGI Scripting,” explores how to use Perl specifically for creating Web server–based CGI scripts.

Day 17, “Managing Files and Directories,” is an extension of the chapter on file input and output; this chapter explores how to work with file systems, including navigating directory hierarchies and renaming and moving files.

Day 18, “Perl and the Operating System,” explores several features of Perl that are specific to particular platforms. Much of Perl was developed for Unix and continues to be Unix-centric; the Windows version of Perl has libraries that take advantage of specific features of the platform. This lesson explores those platform-specific features.

Day 19, “Working with References,” explores one of the more advanced features of Perl—the use of references, which allow more efficient data management and more complex nested data structures.

Day 20, “Odds and Ends,” finishes up the book with a summary of the few features of Perl that weren't covered in the rest of the book.

Day 21, “Exploring a Few Longer Examples,” is the last of the longer example chapters.

Conventions Used in This Book

Any word or term that appears on your screen is presented in a monospaced font to mimic the way it looks on your screen:

it will look like this

Text that you should type is presented in a bold monospaced font:

					type in text that looks like this
				

Placeholders for variables and expressions are presented in monospaced italic type.

Note

A Note presents interesting, sometimes technical pieces of information related to the surrounding discussion.


Tip

A Tip offers advice or offers an easier way to do something.


Caution

A Caution advises you of potential problems and helps you steer clear of disaster.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.181.34