FREE Delivery in the UK.
Only 1 left in stock (more on the way).
Dispatched from and sold by Amazon. Gift-wrap available.
Practical mod_perl has been added to your Basket
+ £2.79 delivery
Used: Good | Details
Condition: Used: Good
Comment: Ships from the UK. Former Library books. Shows some signs of wear, and may have some markings on the inside. 100% Money Back Guarantee. Your purchase also supports literacy charities.
Have one to sell?
Flip to back Flip to front
Listen Playing... Paused   You're listening to a sample of the Audible audio edition.
Learn more
See this image

Practical mod_perl Paperback – 2 Jun 2003

5.0 out of 5 stars 2 customer reviews

See all 4 formats and editions Hide other formats and editions
Amazon Price
New from Used from
Kindle Edition
£22.73 £2.58
Note: This item is eligible for click and collect. Details
Pick up your parcel at a time and place that suits you.
  • Choose from over 13,000 locations across the UK
  • Prime members get unlimited deliveries at no additional cost
How to order to an Amazon Pickup Location?
  1. Find your preferred location and add it to your address book
  2. Dispatch to this address when you check out
Learn more
click to open popover

Enter your mobile number or email address below and we'll send you a link to download the free Kindle App. Then you can start reading Kindle books on your smartphone, tablet, or computer - no Kindle device required.

  • Apple
  • Android
  • Windows Phone

To get the free app, enter your mobile phone number.

Product details

  • Paperback: 928 pages
  • Publisher: O'Reilly Media; 1 edition (2 Jun. 2003)
  • Language: English
  • ISBN-10: 0596002270
  • ISBN-13: 978-0596002275
  • Product Dimensions: 17.8 x 4.9 x 23.3 cm
  • Average Customer Review: 5.0 out of 5 stars 2 customer reviews
  • Amazon Bestsellers Rank: 1,952,247 in Books (See Top 100 in Books)
  • Would you like to tell us about a lower price?
    If you are a seller for this product, would you like to suggest updates through seller support?

  • See Complete Table of Contents

Product description

About the Author

Stas Bekman is the author of The mod_perl Guide, the Open Source document that is the basis for this book. Stas is a member of the Apache Software Foundation and is a multiple speaker at the O'Reilly Open Source Conference. Stas is also a regular author for

Eric Cholet is a member of the Apache Software Foundation and the Paris Perl Mongers. He is technical director of Logilune, a Paris-based company that he co-founded in 1987, and a speaker at the O'Reilly Open Source Conference.

Excerpt. © Reprinted by permission. All rights reserved.

CHAPTER 6 - Coding with mod_perl in Mind

This is the most important chapter of this book. In this chapter, we cover all the nuances the programmer should know when porting an existing CGI script to work under mod_perl, or when writing one from scratch.

This chapter’s main goal is to teach the reader how to think in mod_perl. It involves showing most of the mod_perl peculiarities and possible traps the programmer might fall into. It also shows you some of the things that are impossible with vanilla CGI but easily done with mod_perl.

Before You Start to Code
There are three important things you need to know before you start your journey in a mod_perl world: how to access mod_perl and related documentation, and how to develop your Perl code when the strict and warnings modes are enabled.

Accessing Documentation
mod_perl doesn’t tolerate sloppy programming. Although we’re confident that you’re a talented, meticulously careful programmer whose programs run perfectly every time, you still might want to tighten up some of your Perl programming practices.

In this chapter, we include discussions that rely on prior knowledge of some areas of Perl, and we provide short refreshers where necessary. We assume that you can already program in Perl and that you are comfortable with finding Perl-related information in books and Perl documentation. There are many Perl books that you may find helpful. We list some of these in the reference sections at the end of each chapter.

If you prefer the documentation that comes with Perl, you can use either its online version or the perldoc utility, which provides access to the documentation installed on your system. To find out what Perl manpages are available, execute:

panic% perldoc perl

For example, to find what functions Perl has and to learn about their usage, execute:

panic% perldoc perlfunc

To learn the syntax and to find examples of a specific function, use the -f flag and the name of the function. For example, to learn more about open( ), execute:

panic% perldoc -f open

The perldoc supplied with Perl versions prior to 5.6.0 presents the information in POD (Plain Old Documentation) format. From 5.6.0 onwards, the documentation is shown in manpage format.

You may find the perlfaq manpages very useful, too. To find all the FAQs (Frequently Asked Questions) about a function, use the -q flag. For example, to search through the FAQs for the open( ) function, execute:

panic% perldoc -q open

This will show you all the relevant question and answer sections.

Finally, to learn about perldoc itself, refer to the perldoc manpage:

panic% perldoc perldoc

The documentation available through perldoc provides good information and examples, and should be able to answer most Perl questions that arise.

Chapter 23 provides more information about mod_perl and related documentation.

The strict Pragma
We’re sure you already do this, but it’s absolutely essential to start all your scripts and modules with:

use strict;

It’s especially important to have the strict pragma enabled under mod_perl. While it’s not required by the language, its use cannot be too strongly recommended. It will save you a great deal of time. And, of course, clean scripts will still run under mod_cgi! In the rare cases where it is necessary, you can turn off the strict pragma, or a part of it, inside a block. For example, if you want to use symbolic references (see the perlref manpage) inside a particular block, you can use no strict 'refs';, as follows:

use strict;
no strict 'refs';
my $var_ref = 'foo';
$$var_ref = 1;

Starting the block with no strict 'refs'; allows you to use symbolic references in the rest of the block. Outside this block, the use of symbolic references will trigger a runtime error.

Enabling Warnings
It’s also important to develop your code with Perl reporting every possible relevant warning. Under mod_perl, you can turn this mode on globally, just like you would by using the -w command-line switch to Perl. Add this directive to httpd.conf:

PerlWarn On

In Perl 5.6.0 and later, you can also enable warnings only for the scope of a file, by adding:

use warnings;

at the top of your code. You can turn them off in the same way as strict for certain blocks. See the warnings manpage for more information.

We will talk extensively about warnings in many sections of the book. Perl code written for mod_perl should run without generating any warnings with both the strict and warnings pragmas in effect (that is, with use strict and PerlWarn On or use warnings).

Warnings are almost always caused by errors in your code, but on some occasions you may get warnings for totally legitimate code. That’s part of why they’re warnings and not errors. In the unlikely event that your code really does reveal a spurious warning, it is possible to switch off the warning.

Exposing Apache::Registry Secrets
Let’s start with some simple code and see what can go wrong with it. This simple CGI script initializes a variable $counter to 0 and prints its value to the browser while incrementing it:

#!/usr/bin/perl -w
use strict;
print "Content-type: text/plain\n\n";
my $counter = 0;
for (1..5) {
increment_counter( );
sub increment_counter {
print "Counter is equal to $counter !\n";
When issuing a request to /perl/ or a similar script, we would expect to see
the following output:

Counter is equal to 1 !
Counter is equal to 2 !
Counter is equal to 3 !
Counter is equal to 4 !
Counter is equal to 5 !

And in fact that’s what we see when we execute this script for the first time. But let’s
reload it a few times.... After a few reloads, the counter suddenly stops counting from
1. As we continue to reload, we see that it keeps on growing, but not steadily, starting almost randomly at 10, 10, 10, 15, 20..., which makes no sense at all!

Customer reviews

Share your thoughts with other customers
See all 2 customer reviews

Top customer reviews

30 September 2003
Format: Paperback
2 people found this helpful
|Comment|Report abuse
16 March 2004
Format: Paperback
3 people found this helpful
|Comment|Report abuse

Most helpful customer reviews on 4.6 out of 5 stars 7 reviews
John Dunlap
5.0 out of 5 starsTruly Exceptional
3 August 2013 - Published on
Verified Purchase
One person found this helpful.
A Williams
4.0 out of 5 starsUseful, informative volume on mod_perl
19 February 2004 - Published on
Format: Paperback
15 people found this helpful.
David Cross
5.0 out of 5 starsDefinitive guide to mod_perl administration
16 March 2004 - Published on
Format: Paperback
10 people found this helpful.
Egor Shipovalov
4.0 out of 5 starsmod_perl from the horse's mouth
11 November 2004 - Published on
Format: Paperback
6 people found this helpful.

Where's My Stuff?

Delivery and Returns

Need Help?