Errata

Perl Cookbook

Errata for Perl Cookbook, Second Edition

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed
Page 12
middle of page (2nd last line of code)

defined(read(FH, $buf, $count) or die "read failed: $!"

NOW READS:
defined(read(FH, $buf, $count)) or die "read failed: $!"

Anonymous    Dec 01, 2003
Printed
Page 21
First sentence under heading 'Discussion'

'tildas'

NOW READS:
'tildes'

Anonymous    Aug 01, 2005
Printed
Page 31
example code within section "Solution"

The comments "last word guaranteed to cap" and "first word guaranteed to cap" HAVE BEEN SWAPPED
in order to match the substitiution commands they belong to.

Anonymous    Dec 01, 2003
Printed
Page 56
19th line of code

The line:
"closure args needed for void prototyping."
is part of the comment line above and HAS BEEN REFORMATTED accordingly.

Anonymous    Dec 01, 2003
Printed
Page 63
last line

The line:
$rounded = sprintf("%.2f"", $unrounded);

NOW READS:
$rounded = sprintf("%.2f", $unrounded);

Anonymous    Dec 01, 2003
Printed
Page 70
bottom of the page -

use charnames ":full";
print "2003 is N{ROMAN NUMERAL ONE THOUSAND}" x 2, "N{ROMAN NUMERAL
THREE}
";

NOW READS:
use charnames ":full";
print "2003 is ", "N{ROMAN NUMERAL ONE THOUSAND}" x 2, "N{ROMAN NUMERAL
THREE}
";

Anonymous    Dec 01, 2003
Printed
Page 91
Table 3-1

"$hours" variable

NOW READS:
"$hour"

Anonymous    Aug 01, 2005
Printed
Page 159
the "open" in "fewer than three arguments to open" just above

Example 5-1 is a function name and NOW APPEARS in a code font.

Anonymous    Aug 01, 2005
Printed
Page 195
last paragraph

"The /m modifier allows ^ and $ to match immediately before and after an embedded newline, respectively."

It ought to read "after and before". The example in the next line correctly states "/^=head[1-7]/m would match ... right after a newline ..."

Anonymous    Dec 01, 2006
Printed
Page 195
last paragraph

"The /m modifier allows ^ and $ to match immediately before and after an embedded newline, respectively."

It ought to read "after and before". The example in the next line correctly states "/^=head[1-7]/m would match ... right after a newline ..."

Anonymous    Sep 01, 2007
Printed
Page 223
5th comment line in main code block

is so, the negation failed

NOW READS:
if so, the negation failed

Anonymous    Aug 01, 2005
Printed
Page 237
fifth item from top

verticle

NOW READS:
vertical

page 369- Example 9-6 has been corrected and NOW READS:

---
#!/usr/bin/perl
# symirror - build spectral forest of symlinks

use warnings;
use strict;

use Cwd qw(realpath);
use File::Find qw(find);

die "usage: $0 realdir mirrordir" unless @ARGV == 2;

our $SRC = realpath $ARGV[0];
our $DST = realpath $ARGV[1];

my $oldmask = umask 077; # in case was insanely uncreatable
chdir $SRC or die "can't chdir $SRC: $!";
unless (-d $DST) {
mkdir($DST, 0700) or die "can't mkdir $DST: $!";
}
find {
wanted => &shadow,
postprocess => &fixmode,
} => ".";
umask $oldmask;

sub shadow {
(my $name = $File::Find::name) =~ s!^./!!; # correct name
return if $name eq ".";
if (-d) { # make a real dir; we'll copy mode later
mkdir("$DST/$name", 0700)
or die "can't mkdir $DST/$name: $!";
} else { # all else gets symlinked
symlink("$SRC/$name", "$DST/$name")
or die "can't symlink $SRC/$name to $DST/$name:
$!";
}
}

sub fixmode {
my $dir = $File::Find::dir;
my $mode = (stat("$SRC/$dir"))[2] & 07777;
chmod($mode, "$DST/$dir")
or die "can't set mode on $DST/$dir: $!";
}

Anonymous    Dec 01, 2003
Printed
Page 243
Fourth paragraph, beginning "That means ....", middle line

"... when stacking functions calls ..."

NOW READS:
"... when stacking function calls ..."

Anonymous    Aug 01, 2005
Printed
Page 251
First paragraph of Solution

placing the mode in the second argument:

NOW READS:
place the mode in the second argument:

Anonymous    Aug 01, 2005
Printed
Page 263
2nd paragraph

If don't have a filehandle

NOW READS:
If you don't have a filehandle

Anonymous    Aug 01, 2005
Printed
Page 265
Paragraph 2 in the Solution of recipe 7.11, "Creating Temporary Files" says

use File::Temp qw/ tempdir /;
$fh = tempfile(); # just the handle

change this to

use File::Temp qw(tempfile);
$fh = tempfile(); # just the handle

We're telling people to use "tempfile" but we're importing "tempdir".
The change lets us import "tempfile".

the second block of code in the Solution has similar problems. Change

use File::Temp qw/ tempdir /;
# or specify a directory
$dir = tempdir( CLEANUP => 1 );
($fh, $filename) = tempfile( DIR => $dir );

to:

use File::Temp qw(tempdir);
$dir = tempdir( CLEANUP => 1 );
# or specify a directory
use File::Temp qw(tempfile);
($fh, $filename) = tempfile( DIR => $dir );

Anonymous    Dec 01, 2006
Printed
Page 281
1st paragraph

fnctl

NOW READS:
fcntl

Anonymous    Aug 01, 2005
Printed
Page 328
3rd para

Section starts:

If you want to ignore the system config file when the user has his own, test the return of the do.

do "$APPDFLT/sysconfig.pl";
or
do "$ENV{HOME}/.myprogrc";

The test is the wrong way around. The test as coded will never run the user's code as the system config file should always exist so the "or" will never be triggered. The test should run the user's file first.

Additionally a note ought to be added to the effect that any error in the user's file will result in the system file being used - possibly silently. :-(

Note from the Author or Editor:
Switch the order of the two do arguments per the description.

Dave Saville  May 10, 2013 
Printed
Page 330
comment in code block near middle of page

Change:
# the real uid is in stored in
to:
# the real uid is stored in

Anonymous    Dec 01, 2006
Printed
Page 354
main code block

$len = sysread IN, $buf, $blksize);

NOW READS:
$len = sysread IN, $buf, $blksize;

Anonymous    Aug 01, 2005
Printed
Page 372
last line

The empty lines before the last line:
}
should be removed.

Anonymous    Dec 01, 2006
Printed
Page 394
Code under title "Using local() for temporary values for globals"

More specifically the line having the comment "pass filehandle by IO reference."

"*IO{FH}"

NOW READS:
"*FH{IO}"

Anonymous    Aug 01, 2005
Printed
Page 410
Near page bottom, line of code beginning "return ..."

return $errcount ? undef() : %record;
Should be:
return $errcount ? undef : \%record;

Here's the entire piece of code, corrected:

sub cite {
my (%record, $errcount);
...
return $errcount ? undef : \%record;
}
$op_cit = cite($bid) or die "couldn't make a reference
";

Anonymous    Sep 01, 2007
Printed
Page 419
Near mid-page, line below "Print &$counter1 ..."

the stated output should have a line with a 0 first.
The old was:
print &$counter1, " ", &$counter2, "
";

1
2
3
4
5 0

and should read instead

print &$counter1, " ", &$counter2, "
";

0
1
2
3
4
5 0

Anonymous    Dec 01, 2006
Printed
Page 447
Paragraph beginning "Line 4 assigns..."

"Cards::Poke::shuffle"
should be
"Cards::Poker::shuffle"

Anonymous    Dec 01, 2006
Printed
Page 450
Paragraph above "@EXPORT_OK"

To load the module at compile time but request that no symbols
be exported, use the special form
C<use Exporter ()>, with empty parentheses.

And it should read:

To load the module at compile time but request that no symbols be
exported, use the special form
C<use Your Module ()>, supplying empty parentheses for the import list.

Anonymous    Dec 01, 2006
Printed
Page 489
Second from last line on page

Line
% tar xf Some-Module-4.54
should read
% tar xf Some-Module-4.54.tar

Anonymous    Dec 01, 2006
Printed
Page 495
modname subroutine (line 68)

if (index($_, $Start_Dir . "/") = = 0) {
This generates an error at compile time. Should be modified to read:
if (index($_, $Start_Dir . "/") == 0) {

Anonymous    Dec 01, 2006
Printed
Page 522
Second line of code under title Solution

Line
$obj->$methname(10); # invokes $ob->flicker(10);
should read
$obj->$methname(10); # invokes $obj->flicker(10);

Many examples use '$obj' as the example object reference variable. This page uses
two different example variable names, '$obj' under Solution and '$ob' under
Discussion.

Anonymous    Dec 01, 2006
Printed
Page 549
Item 'e' in the notes under Table 14-1

Change
Provising you have an ANSI C compiler
to
Providing you have an ANSI C compiler

Anonymous    Dec 01, 2006
Printed
Page 567
2nd line of code

RaiseError > 1

NOW READS:
RaiseError => 1

Anonymous    Dec 01, 2003
Printed
Page 583
3rd paragraph

Change:
The simplest user interface is what we are called
to, say:
The simplest user interface is what are called

Anonymous    Dec 01, 2006
Printed
Page 589
2nd last paragraph

Change:
module Term::Cap module
to, say:
Term::Cap module

Anonymous    Dec 01, 2006
Printed
Page 591
8th last line of code

Change:
print colored("venom lack
", "red", on_black");
to:
print colored("venom lack
", "red", "on_black");

Anonymous    Sep 01, 2007
Printed
Page 626
See Also

'The section on The section on "Talking to yourself" ...'
should say:
'The section on "Talking to yourself" ...'

Anonymous    Dec 01, 2006
Printed
Page 699
Bottom of the first 1/3 section of ex 17-6

Line 38 currently reads:

if ($client = = $server) {

Line 38 should read:

if ($client == $server) {

Anonymous    Dec 01, 2006
Printed
Page 699-700
Middle of ex 17-6

Lines 88-89 currently read:

if ($rv = = length $outbuffer{$client} ||
$! = = POSIX::EWOULDBLOCK )

Lines 88-89 should read:

if ($rv == length $outbuffer{$client} ||
$! == POSIX::EWOULDBLOCK )

Anonymous    Dec 01, 2006
Printed
Page 747
2nd paragraph in "Discussion" section

"It looks strange to see all those chained method invocation"
should read:
"It looks strange to see all those chained method invocations"

Anonymous    Sep 01, 2007
Printed
Page 754
6th last line

The line:

# Iterate over addresses give on command line.
should read:
# Iterate over addresses given on command line.

Anonymous    Sep 01, 2007
Printed
Page 783
"Problem" paragraph, 5th line

"display a list of product to edit"
should read:
"display a list of products to edit"

Anonymous    Sep 01, 2007
Printed
Page 823
Recipie 20.19

The module does not work on nested tables.

Anonymous   
Printed
Page 858
4th paragraph, last sentence

this strict separation of business from presentation logic...

NOW READS:
This strict separation of business from presentation logic...

Anonymous    Dec 01, 2003
Printed
Page 859
last code snipet on that page

[% person.key %] = [% person.value %].

NOW READS:
[% person.key %] is [% person.value %].


AND

The C<key> and C<person> methods can be called on a hash loop

NOW READS:
The C<key> and C<value> methods can be called on a hash loop

Anonymous    Aug 01, 2005
Printed
Page 864
Middle of page, under <book id="2">

The text for the <title> element for the Perl & LWP book previously appeared as "Perl & ".
It NOW READS "Perl & LWP".

Anonymous    Aug 01, 2005
Printed
Page 865
5th paragraph, 2nd last sentence

Unicode letters...are all acceptable in element and attribute name, ...

NOW READS:
Unicode letters...are all acceptable in element and attribute names, ...

868) 2nd paragraph, 2nd sentence;
The most important action you do with a schemas...

NOW READS:
The most important action you do with schemas...

Anonymous    Dec 01, 2003
Printed
Page 890
First line

Use closures to let XSLT access to Perl variables...

NOW READS:
Use closures to let XSLT access Perl variables...

Anonymous    Dec 01, 2003
Printed
Page 891
Recipe 22.9 "Problem" sentence

You want to create an Rich Site Summary...

NOW READS:
You want to create a Rich Site Summary...

Anonymous    Dec 01, 2003