Introduction

This is the book I wish I’d had when I was learning Perl. The problem with most Perl books is that they are written by Perl programmers for Perl programmers. This makes things difficult for the C and C++ programmer coming to Perl.

This book explains Perl in a language you can understand. Good, simple programming style is stressed so that you can write not just Perl programs, but working, maintainable Perl programs.

You will find that this book is shorter, yet conveys more, than most other Perl books. That’s because this book doesn’t treat you like a dummy and doesn’t reproduce a lot of online documentation. (I’ll tell you how to find it online.) Because of this, you are getting all the information you need in a compact, well-formed package.

Perl is a language designed to process text. Some uses for Perl are

  • Report writing— The basic business program is “read it, munch it, sort it, and write a report.” Perl makes it simple and easy to write such programs.

  • System administration— Most UNIX and Linux configuration files are text. With Perl, it is easy to manipulate these files.

  • Creation of dynamic web pages— If you’ve ever filled in a web form and clicked Submit, you’ve probably used a Perl program. Perl’s text-handling capabilities make it superb for generating forms and web pages. Add to this Perl’s built-in database accessing capabilities, and you have a language that provides a complete solution for your web development needs.

Who Should Read This Book

As suggested previously, this book is written for the seasoned C or C++ programmer who wants to learn Perl. It does not teach programming per se but instead assumes that you already know how to program and that you know how to program in C or C++.

Overview

Each chapter in Perl for C Programmers is briefly described here.

Chapter 1, “Exploring Perl

Perl is more than just a language. Perl’s online documentation and a repository called CPAN hold thousands of Perl modules. This chapter describes how to exploit these features of the language.

In addition, the mechanics of writing, running, and debugging a Perl program are discussed.

In short, this chapter covers everything you need to know about programming Perl except the programming part.

Chapter 2, “Perl Basics

C and Perl share many of the same basic operations and much of the same syntax. (They just use different words.) This chapter describes these simple operations and syntax.

Chapter 3, “Arrays

Perl has a flexible array data type. This chapter teaches you about the various Perl array manipulation operations. These include merging two arrays, using the push/pop operators, manipulating array slices, filtering with the grep function, and other array manipulations.

Chapter 4, “Regular Expressions

One of the most powerful features of Perl are regular expressions. They are used for text matching and manipulation. Regular expressions are a language unto themselves. This chapter examines them in detail.

Chapter 5, “Perl’s New Syntax

Perl has a number of new and unique syntax elements that have no equivalent in C or C++. This chapter explores things such as die, redo, foreach, and other Perl-specific operations.

Chapter 6, “Hashes, References, and Complex Data Structures

Perl has a variable type that’s not available in C; it is the hash. This chapter introduces you to hashes and shows you how to use them. Subjects covered include the basic hash, the key and values functions, iterating through hashes, erasing elements, and other hash-related operations.

Chapter 7, “>Subroutines and Modules

Writing a subroutine in Perl is not as simple as it is under C. This chapter describes how to write subroutines, pass parameters, and handle other special subroutine requirements.

The chapter then takes these subroutines and groups them together to form a package. Unfortunately, Perl’s package logic is not as simple as the one that C uses, but this chapter makes it simple.

Chapter 8, “Object-Oriented Programming

Perl has the capability to define your own classes. This chapter teaches you basic Perl object-oriented techniques and how to define your own object-oriented package.

Chapter 9, “Advanced I/O

Perl has an I/O structure similar to C, but with many additional features. A number of tricks and surprises also lurk in the I/O system. This chapter covers them all.

Chapter 10, “POD

POD is the Perl internal documentation format. This chapter shows you the basic POD syntax as well as gives you information on the standard format that should be used for program documentation.

This chapter takes you on a tour through a complete POD document to see how it is formatted and discusses each of the formatting operators.

Chapter 11, “Under the Hood

C and C++ hide many details from you. Perl is no different. But sometimes it’s a good idea to look under the hood and understand how the language operates. This chapter discusses many of the details skipped over in previous chapters.

Chapter 12, “CGI Programming

Perl is the language of the web. This chapter covers the programming that runs web forms (CGI programming). Writing and debugging these types of programs brings its own unique set of challenges. Here’s where you find out how to meet these challenges.

Chapter 13, “Creating GUIs with Tk

Tk is the portable GUI module available for Perl. This chapter tells you how to create, debug, and run GUI-based Perl programs.

Chapter 14, “Combining C and Perl with Inline::C

With the Inline module, you can embed a C or C++ program inside your Perl program. Thus you can have a Perl function call a C subroutine. You can even have a Perl function call a C subroutine that calls a Perl function.

Chapter 15, “Putting It All Together

In this chapter, you take all your Perl know-how and make a real program. In this case, it’s a program to organize your software. The program uses the Perl interface to manipulate a simple database (called DB_File).

Because Perl is so flexible, the program comes with three user interfaces: command-line tools, a Tk GUI version, and a web-based interface.

Chapter 16, “Cookbook

Perl can do many different things. This chapter shows you how to design and implement a number of useful programs. This cookbook contains examples of many different types of programs. Hopefully, one will be similar to what you plan on doing in Perl.

Chapter 17, “Creating Modules

Perl’s real strength is in its extensive set of modules. There are some things you just can’t find a module for, however, in which case you have to write your own. This chapter shows you how.

Conventions

This book follows a few typographical conventions:

  • Commands, program text, functions, variables, and other “computer language” are set in a monospaced font—for example, $size or use warnings;.

  • In computer code or syntax, placeholder items that are set or entered by the user are set in monospaced italics —for example, $line =~ s/<old >/<new >/<flag>;.

  • In computer code or syntax, optional items are in brackets—for example, cat [file].

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

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