Have one to sell? Sell yours here
Perl in a Nutshell (In a Nutshell (O'Reilly))
 
 
Tell the Publisher!
I’d like to read this book on Kindle

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Perl in a Nutshell (In a Nutshell (O'Reilly)) [Paperback]

Nathan Patwardhan , Ellen Siever , Stephen Spainhour
5.0 out of 5 stars  See all reviews (5 customer reviews)

Available from these sellers.


‹  Return to Product Overview

Product Description

Amazon.co.uk Review

The latest edition to the O'Reilly range of Perl manuals proves once again the mastery the company have when it comes to producing professional reference material.

As part of their desktop reference series, Perl in a Nutshell is everything programmers have come to expect: clear, concise and no-nonsense information on the subjects which matter.

Reminiscent of the Perl man pages, the book covers a wide variety of topics from a brief (yet useful) introduction to the language through a breakdown of the standard modules, to facilities including Tcl, Sockets programming, the LWP libs and even the Win32 interface.

Supported by a heavy duty index which makes finding the right piece of information a breeze, this 650-page tome is bound to see some serious action from any Perl programmer with a busy work schedule.

The fact that it bills itself as a quick reference goes some way to showing that Perl In A Nutshell is not a compact beginners guide--if you want one of those try O'Reilly's Learning Perl. However, for the workaday programmer who needs an elbow-side reference manual or the occasional coder looking for a memory jogger, this book is worth it's weight in gold.

Review

"What can I say? This is a nutshell book, and thus the quality is excellent. Being a regular user of the 1st edition of Perl in a Nutshell (does that say more about the book or my perl programming I wonder ...) I fully expected this to be as good if not better. I was not disappointed. " Northampton Linux User group --This text refers to an alternate Paperback edition.

Product Description

Perl in a Nutshell is a comprehensive reference guide to the Perl programming language. This book covers all the core features of the language. It ranges widely through the Perl programmer's universe, gathering together in convenient form a wealth of information about Perl itself and its application to CGI scripts, network programming, database interaction, and graphical user interfaces. It also gives detailed coverage about using Perl within a Win32 environment.

This book assembles more information about the language in one place than any other reference work. Here are just some of the topics covered in the book:

  • Basic language reference
  • Introduction to using Perl modules
  • Perl and CGI: CGI basics, CGI.pm, mod_perl
  • DBI, the database-independent API for Perl
  • Sockets programming in Perl
  • LWP, the library for World Wide Web programming in Perl
  • The Net::* modules

As part of the successful "in a Nutshell" series of books from O'Reilly & Associates, Perl in a Nutshell is for readers who want a single reference for all their needs.

About the Author

Ellen Siever is a writer and editor specializing in Linux and other open source topics. In addition to Linux in a Nutshell, she co-authored Perl in a Nutshell. She is a long-time Linux and Unix user, and was a programmer for many years until she decided that writing about computers was more fun.

Stephen Spainhour co-authored Webmaster in a Nutshell, Perl in a Nutshell, 1st Edition, and contributed to many other OReilly titles. He is an avid fan of professional tennis, and when hes not checking for tennis scores on the Web, he enjoys cooking, electronic music, troubleshooting his home-built PC, and watching too much television.

Excerpted from Perl in a Nutshell by Ellen Siever, Stephen Spainhoura, Nathan Patwardhan. Copyright © 2002. Reprinted by permission. All rights reserved.

Chapter 4 - The Perl Language
This chapter is a quick and merciless guide to the Perl language itself.If you’re trying to learn Perl from scratch and would prefer to be taught rather than to have things thrown at you,then you might be better off with Learning Perl, 3rd Edition by Randal L.Schwartz and Tom Phoenix.However,if you already know some other programming languages and just want to learn the particulars of Perl, this chapter is for you. Sit tight,and forgive us for being terse —we have a lot of ground to cover.
If you want a more complete discussion of the Perl language and its idiosyncrasies (and we mean complete ),see Programming Perl,3rd Edition by Larry Wall,Tom Christiansen,and Jon Orwant.

Program Structure
Perl is a particularly forgiving language,as far as program layout goes.There are no rules about indentation, newlines,etc.Most lines end with semicolons,but not everything has to.Most things don ’t have to be declared, except for a couple of things that do.Here are the bare essentials:

Whitespace
Whitespace is required only between items that would otherwise be confused as a single term.All types of whitespace —spaces,tabs,newlines,etc.—are equivalent in this context.A comment counts as whitespace.Different types of whitespace are distinguishable within quoted strings, formats,and certain line-oriented forms of quoting.For example,in a quoted string,a newline,a space,and a tab are interpreted as unique characters.

Semicolons
Every simple statement must end with a semicolon.Compound statements contain brace-delimited blocks of other statements and do not requireterminating semicolons after the ending brace.A final simple statement in a block also does not require a semicolon.

Declarations
Only subroutines and report formats need to be explicitly declared.All other user-created objects are automatically created with a null or 0 value unless they are defined by some explicit operation such as assignment.The –w command-line switch will warn you about using undefined values.
You may force yourself to declare your variables by including the use strict pragma in your programs (see Chapter 8 for more information on pragmas and strict in particular).This causes an error if you do not explicitly declare your variables.

Comments and documentation
Comments within a program are indicated by a pound sign (#).Everything following a pound sign to the end of the line is interpreted as a comment.

Lines starting with =are interpreted as the start of a section of embedded documentation (pod),and all subsequent lines until the next =cut are ignored by the compiler.See the section "Formats "later in this chapter for more information on pod format.

Data Types and Variables
Perl has three basic data types:scalars ,arrays ,and hashes. Scalars are essentially simple variables.They are preceded by a dollar sign ($).A scalar is either a number,a string,or a reference.(A reference is a scalar that points to another piece of data. References are discussed later in this chapter.) If you provide a string in which a number is expected or vice versa,Perl automatically converts the operand using fairly intuitive rules.

Arrays are ordered lists of scalars accessed with a numeric subscript (subscripts start at 0).They are preceded by an "at "sign (@). Hashes are unordered sets of key/value pairs accessed with the keys as subscripts.
They are preceded by a percent sign (%).

Numbers
Perl stores numbers internally as either signed integers or double-precision, floating-point values.Numeric literals are specified by any of the following floating-point or integer formats:

12345
Integer
-54321
Negative integer
12345.67
Floating point
6.02E23
Scientific notation
0xffff
Hexadecimal
0377
Octal
4_294_967_296

Underline for legibility
Since Perl uses the comma as a list separator,you cannot use a comma for improving the legibility of a large number.To improve legibility,Perl allows you to use an underscore character instead.The underscore works only within literal numbers specified in your program,not in strings functioning as numbers or in data read from somewhere else.Similarly,the leading 0x for hex and 0 for octal work only for literals.The automatic conversion of a string to a number does not recognize these prefixes —you must do an explicit conversion.

Be aware that in Perl 5.8,there are many changes in how Perl deals with integers and floating-point numbers.Regardless of how your system handles numbers and conversion between characters and numbers,Perl 5.8 works around system deficiencies to force more accurate number handling.Furthermore,whereas prior to 5.8 Perl used floating-point numbers exclusively in math operations,Perl 5.8 now uses and stores integers in numeric conversions and in arithmetic operations.

String Interpolation
Strings are sequences of characters.String literals are usually delimited by either single (')or double (")quotes.Double-quoted string literals are subject to back-slash and variable interpolation,and single-quoted strings are not (except for \' and \\,used to put single quotes and backslashes into single-quoted strings).You can embed newlines directly in your strings. --This text refers to an alternate Paperback edition.

‹  Return to Product Overview