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 "Corrected".
The following errata were submitted by our customers and approved as valid errors by the author or editor.
| Version |
Location |
Description |
Submitted By |
Corrected |
| Safari Books Online |
APPA
first exercise |
Code sample generates one warning and one error if run with perl -w.
The problem is with the file test.
#!/usr/bin/perl
my @smaller_than_1000 = grep { -s < 1000 } @ARGV;
print map { " $_\n" } @smaller_than_1000;
the -s < is ambiguous to the interpreter, so fails when the interpreter tries to resolve < to the first part of a diamond operator.
grep { (-s) < 1000 } @ARGV; # works
grep { 1000 > -s } @ARGV; # also works
The same applies for the one-liner 2nd example:
print map { " $_\n" } grep { -s < 1000 } @ARGV;
This is covered in Programming Perl pg 97.
Thanks
Note from the Author or Editor: Fix as
grep { (-s) < 1000 } @ARGV; # works
|
Anonymous |
|
| Printed |
Page 7
Top of page |
Remove the ending right parenthesis ")" after "list context"
|
Anonymous |
Feb 2007 |
| Printed |
Page 11
second footnote |
"Although we don't go into here"
should be
"Although we don't go into it here".
|
Anonymous |
Feb 2007 |
| Printed |
Page 13
3rd paragraph, last sentence |
The value of $basename should be "plan7.rtf", not "plan 7.rtf". No embedded space.
|
Anonymous |
Feb 2007 |
| Printed |
Page 17
last paragraph |
"One way to fix this is to add a BEGIN block around the push" should be "One
way to fix this is to add a BEGIN block around the unshift".
|
Anonymous |
|
| Printed |
Page 41
Last paragraph - code |
['The Professor', [qw(sunscreen water_bottle slide_rule radio) ]],
should be
['The Professor', [qw(sunscreen water_bottle slide_rule batteries radio) ]],
|
Anonymous |
Feb 2007 |
| Printed |
Page 60
the code at the bottom of the page, |
vfor 'The Professor':
[qw(sunscreen water_bottle slide_rule radio)]
should be:
[qw(sunscreen water_bottle slide_rule radio batteries)]
|
Anonymous |
Feb 2007 |
| Printed |
Page 80
Second paragraph under "The Improved Way" |
Currently reads:
----
If the scalar already has a value, this doesn't work because Perl won't stomp on our
data.
----
This should read:
----
If the scalar already has a value, this doesn't work because Perl won't stomp on our
data. Perl tries to use the value in C<$log_fh> as a symbolic reference, so it tries
to print to the filehandle named C<5>. Under C<use strict>, this is a fatal error.
----
|
Anonymous |
|
| Printed |
Page 80
4th paragraph, not including code blocks |
In the 10/07 printing, it currently reads:
'...Perl tries to use the value in C<$log_fh> as a symbolic reference, so it tries to print to the filehandle named C<5>. Under C<use strict>, this is a fatal error.'
The 'C<...>' text is in a larger monospace font never before used before in the book. I saw a note about this in errata for the most recent printing saying to *add* this sentence. I'm guessing they meant that C<alpha> signifies that 'alpha' should be formatted as code.
Note from the Author or Editor: Remove the C<> formatting codes and print their contents in the code font.
|
Anonymous |
|
| Printed |
Page 83
First code example in 'Anonymous IO::File Objects' |
The arguments to the calls to IO::File->new are single-quoted strings but the strings contain
references to $file and $out. I'm guessing interpolation was expected, in which case the strings
should be double-quoted.
Note from the Author or Editor: Change to double quotes as noted in calls to IO::File->new().
|
Anonymous |
|
| Printed |
Page 85
First code example under IO::Tee |
The first open statement:
or die "Could not open castaways.log;
should read
or die "Could not open castaways.log"
Note from the Author or Editor: Should read:
or die "Could not open castaways.log";
|
Anonymous |
|
| Printed |
Page 86
Top half of page, 1st code example folowwing paragraph beginning: "That's not all" |
The last statement, "print," causes a warning that says the filehandle is opened for input only.
It also causes an additional and unwanted output operation to the intended output files because
the output is first accomplished via the preceding line:
my $message = <$tee_fh>;
This is consistent with the documentation for the IO:Tee module at the end of the paragraph
beginning with, "The second way."
Note from the Author or Editor: Remove the `print` line, which causes double output.
|
Anonymous |
|
| Printed |
Page 91
Last paragraph |
"Professor is position 2"
should read,
"Professor is position 3"
Note from the Author or Editor: Change as noted
|
Anonymous |
|
| Printed |
Page 95
as shown |
In the section "Building Recursively Defined Data" in Chapter 9, a code bit reads:
#####
my $skipper_home = {
'.cshrc' => undef,
Please_rescue_us.pdf => undef,
Things_I_should_have_packed => undef,
bin => {
navigate => undef,
discipline_gilligan => undef,
eat => undef,
},
};
#########
It should quote the keys for 'Please_rescue_us.pdf' and 'Things_I_should_have_packed', like this:
#########
my $skipper_home = {
'.cshrc' => undef,
'Please_rescue_us.pdf' => undef,
'Things_I_should_have_packed' => undef,
bin => {
navigate => undef,
discipline_gilligan => undef,
eat => undef,
},
};
#########
|
Anonymous |
|
| Printed |
Page 99
code after 1st paragraph |
[10/07] printing
my %directory = %$data;
is unnecessary. Also, 3rd line later:
dump_data_for_path("$path/$_", $data->{$_});
Exercises Ch. 9 #4 pp 232-233, similar changes
Note from the Author or Editor: We don't really need it, but there's no harm. It's only there to avoid dereferencing syntax. We can change this in the next edition.
|
Anonymous |
|
| Printed |
Page 128
towards the top of page |
The only difference between a class method and an instance method is
whether the first parameter is an instance (a blessed reference) or a
class name (a string).
should read instead:
The only difference between a class method and an instance method is
whether the first parameter is a class name (a string) or an instance (a
blessed reference).
|
Anonymous |
|
| Printed |
Page 132
First code example inside paragraph starting "Let's make a sheep" |
my $lost = bless { Name => 'Bo', Color => 'white' }, Sheep;
should read
my $lost = bless { Name => 'Bo', Color => 'white' }, 'Sheep';
Note from the Author or Editor: Change as noted
|
Anonymous |
|
| Printed |
Page 137
top of page |
"We've been burned in the past when a setter became a getter because
another function returned more parameters than expected after an
upgrade."
should read:
"We've been burned in the past when a getter became a setter because
another function returned more parameters than expected after an
upgrade."
|
Anonymous |
|
| Printed |
Page 137
4th line of the first paragraph |
"setter became a getter"
should read
"getter became a setter"
Note from the Author or Editor: Change as noted
|
Anonymous |
|
| Printed |
Page 161
first paragraph |
All references to subclasses should be turn to superclasses. You don't inherit
from subclasses.
Note from the Author or Editor: Change as noted
|
Anonymous |
|
| Printed |
Page 174
last code sample before "README" section |
$ make ziptest
should be
$ make zipdist
|
Anonymous |
|
| Printed |
Page 197
last code example from section "Writing Tests with Test::More" |
While talking about the string form of the regular expression, the second argument to like() is still given as a regex reference:
like($subtract, qr/^-?0$/, '-3 + 3 == 0');
This should read
like($subtract, '/^-?0$/', '-3 + 3 == 0');
instead.
Note from the Author or Editor: This is the line of code above the paragraph which is above the heading "Testing Object-Oriented Features". That line of code should read:
like($subtract, '^-?0$', '-3 + 3 == 0');
|
Anonymous |
|
| Printed |
Page 214
section "Writing Your Own Test::* Modules", last paragraph, first sentence |
[...], how we do we test the test?
should probably read
[...], how do we test the test?
Note from the Author or Editor: Change as noted
|
Anonymous |
|
| Printed |
Page 221
first exercise |
Code sample generates one warning and one error if run with perl -w.
The problem is with the file test.
#!/usr/bin/perl
my @smaller_than_1000 = grep { -s < 1000 } @ARGV;
print map { " $_
" } @smaller_than_1000;
the -s < is ambiguous to the interpreter, so fails when the interpreter tries to resolve < to the first part of a diamond operator.
grep { (-s) < 1000 } @ARGV; # works
grep { 1000 > -s } @ARGV; # also works
The same applies for the one-liner 2nd example:
print map { " $_
" } grep { -s < 1000 } @ARGV;
Note from the Author or Editor: Change to have parens around the -s calls. All -s should be (-s).
|
Anonymous |
|
| Printed |
Page 221
excercise 1 answer for Chapter 2 |
my @smaller_than_1000 = grep { -s < 1000 } @ARGV;
should be:
my @smaller_than_1000 = grep { -s $_ < 1000 } @ARGV;
|
Anonymous |
Feb 2007 |
| Printed |
Page 229
Bottom section of the page |
The answer to exercise 8-2 doesn't work with the current versions of Perl and IO::File. I'm not sure if this is a change in IO::File or if the answer as written never worked.
The problem line is this:
my $handle = $output_handles{$name} ||=
IO::File->open(">$name.info") || die "Cannot create $name.info: $!";
As written, that produces this error: Can't use string ("IO::File") as a symbol ref while "strict refs" in use at /home/telemachus/lib/perl5/5.10.0/i686-linux/IO/File.pm line 185, <> line 1.
However, if you change IO::File->open to IO::File->new everything works just fine.
Note from the Author or Editor: In the code under "Exercise 2", change the line:
IO::File->open(">$name.info") || die "Cannot create $name.info: $!";
to:
IO::File->new(">$name.info") || die "Cannot create $name.info: $!";
where we replace "open" with "new".
|
Anonymous |
|
| Printed |
Page 231
4th line of code listing |
while( my $file = $dh->read ) {
should read
while( defined(my $file = $dh-> read) ) {
Otherwise the while can potentially abort prematurely atleast for the case where
there is a file named '0' in the directory.
Note from the Author or Editor: Change as noted
|
Anonymous |
|
| Printed |
Page 231
Exercise 2 |
The code of Exercise 2 is not correct.
The Ordinary "is" still faster.
The solution was in the comments to the quoted URL: http://www.perlmonks.com/?node_id=393128
The @files is not known to Benchmark. With the code on p 231 the Ordinary is still faster, but
@files is empty. Probably most clear is to change the q{} to sub {} in the code for the Ordinary
and Schwartzian.
Running with the q{} quoted code of the example:
Benchmark: running Ordinary, Schwartzian for at least 2 CPU seconds...
Ordinary: 2 wallclock secs ( 2.03 usr + 0.00 sys = 2.03 CPU) @ 398461.58/s (n=808877)
Schwartzian: 3 wallclock secs ( 2.04 usr + 0.03 sys = 2.07 CPU) @ 337243.48/s (n=698094)
Changing q{} to sub {} shows the following results
Running with the sub on /etc/* (81 files):
Benchmark: running Ordinary, Schwartzian for at least 2 CPU seconds...
Ordinary: 3 wallclock secs ( 0.38 usr + 1.73 sys = 2.11 CPU) @ 58.77/s (n=124)
Schwartzian: 2 wallclock secs ( 1.21 usr + 0.84 sys = 2.05 CPU) @ 214.63/s (n=440)
Running with the sub on /bin/* (81 files):
Benchmark: running Ordinary, Schwartzian for at least 2 CPU seconds...
Ordinary: 3 wallclock secs ( 0.35 usr + 1.66 sys = 2.01 CPU) @ 129.85/s (n=261)
Schwartzian: 2 wallclock secs ( 1.12 usr + 1.00 sys = 2.12 CPU) @ 416.98/s (n=884)
This is perl, v5.8.6 built for darwin-thread-multi-2level
on Mac OS X 10.4.9 G3 500 MHz.
Note from the Author or Editor: Change as noted.
|
Anonymous |
|
| Printed |
Page 241
Exer 2 solution |
locatime needs to be localtime()
Note from the Author or Editor: Change as noted.
|
Anonymous |
|
| Printed |
Page 244 f.
tests code example |
The test for shuffle() is totally broken.
First of all, the least serious problem is a typo on page 244, next to last line: it should read $shuffled->[$index] instead of $shuffle->[$index] (note: shuffled vs. shuffle).
However, the whole comparing doesn't make any sense. Both $array and $shuffled are references to the same (anonymous) array, and after the array elements have been shuffled both of them still point to that array. Thus comparing their elements means comparing each array element to itself. And of course this leads to $same_count always being `scalar @$array'.
And even if these problems were fixed, the call to cmp_ok() doesn't make sense. All array elements may have retained their position, but they might as well all have changed it; and of course everything in between is also possible. It probably makes most sense here to compare the elements of the _sorted_ original and shuffled arrays.
Note from the Author or Editor: For the code at the bottom of page 244, there are two errors:
The line that reads:
my $shuffled = $array;
should read
my $shuffled = [ @$array ];
And, the second code line from the bottom of the page has an incorrect variable name. The name is written as "$shuffle", but should be "$shuffled" with a "d" at the end:
$same_count++ if $shuffled->[$index] eq $array->[$index];
|
Anonymous |
|
| Printed |
Page 244
3rd paragraph and code below it |
The text mentions making a copy of the array.
In the code below the reference is copied. Both $array and $shuffled therefore still point to
the same data.
The test will not work.
Note from the Author or Editor: The offending line is:
my $shuffled = $array;
That should be:
my $shuffled;
@shuffled = @$array;
|
Anonymous |
|
| Printed |
Page 245
Code |
use Exporter is redundant, use base qw(Exporter) already takes care of that.
Note from the Author or Editor: remove the line that says
use Exporter;
|
Anonymous |
|