Intermediate Perl

Errata for Intermediate Perl

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
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  Jul 28, 2008 
Printed
Page 7
Top of page

Remove the ending right parenthesis ")" after "list context"

Anonymous    Feb 01, 2007
PDF
Page 8
First paragraph, first sentence.

The words "that" and "modules" appear to have been swapped and the word "with" seems superfluous. The sentence currently reads: Throughout this book, we’ll try to identify that modules come with perl (and usually, with which version of perl first included them). This should probably read: Throughout this book, we’ll try to identify modules that come with perl (and usually, which version of perl first included them). (Note that I previously reported an error in this sentence, but did not include removal of the word "with" in that report.)

Mx  Aug 30, 2012 
PDF
Page 10
First paragraph, first sentence, 3rd word.

The line currently reads: We’ve included on the top portion of the documentation to show the most important This is referring to the top part of the output of "perldoc File::Basename". The word "on" is not appropriate. Should probably read: We’ve included the top portion of the documentation to show the most important

Mx  Aug 29, 2012 
Printed
Page 11
second footnote

"Although we don't go into here" should be "Although we don't go into it here".

Anonymous    Feb 01, 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 01, 2007
PDF
Page 15
6th paragraph

Sentence starts with If we have the a recent version of Perl, should also already have Module::CoreList This should probably be: If we have a recent version of Perl, we should also already have Module::CoreList

Note from the Author or Editor:
Changed as noted in r546856.

Marnix A. van Ammers  Aug 19, 2012 
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   
PDF
Page 18
3rd paragraph.

Middle of paragraph seems to be missing the word "do". Line shows as: as friendly since not only we have to change the code but also because it might not be Should probably be: as friendly since not only do we have to change the code but also because it might not be

Mx  Aug 29, 2012 
Printed
Page 20
2nd Paragraph, last sentence

It appears that there is no longer a "country_code" method available in the Business::ISBN module. I am assuming you meant "group_code"?

Note from the Author or Editor:
country_code was correct at the time of printing. The module changed to group_code, the correct term according to the ISBN Agency, after printing.

Lucas Marshall  Oct 07, 2009 
Printed
Page 25
3rd paragraph

"Now instead of copying the entire provision list into the @_ array, we get A SINGLE ELEMENT OF A REFERENCE to that provisions array." shouldn't it say "we get a single element, which is a reference to that provisions array." maybe showing a major lack of my understanding but this doesn't quite make sense to me.

Note from the Author or Editor:
change to "we get a single element which is a reference to that provisions array.".

Lucas Marshall  Oct 07, 2009 
Printed
Page 39
Last paragraph

"When we compare reference with ==" should read "When we compare references with =="

Note from the Author or Editor:
Change as noted

cg  Nov 11, 2012 
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 01, 2007
Printed
Page 50
3rd paragraph

"The show_hash subroutine expects a hash and ..." should read "The show_hash subroutine expects a hash reference and ..."

Note from the Author or Editor:
Change as noted

cg  Nov 11, 2012 
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 01, 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 84
United States

In line 6 IN should be $IN:: 1 while (@handlepairs) { 2 @handlepairs = grep { 3 my ( $IN, $OUT ) = @$_; 4 my $line; 6 defined( $line = <IN> ) and print $OUT $line; 7 8 } @handlepairs;

Note from the Author or Editor:
Fixed in sources (revision 426516)

Anonymous  Dec 13, 2011 
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 135
sub rightmost

The rightmost() function doesn't really find the rightmost match. Just imagine that "Both Gilligan and Ginger like Ginger Ale." The assignment to $position is missing a "my".

Note from the Author or Editor:
I fixed the missing 'my', but I don't see the problem with the first issue.

cg  Nov 21, 2012 
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 151
code

if (-f $path or -l $path) { must read if (-l $path or -f $path) { You must check symbolic links first because otherwise you would populate the tree with the data for the link targets and might also create that circular loop you warn about in the text ... Aside from that, you could use "_" in all following file tests as recommend in "Learning Perl".

Note from the Author or Editor:
Change that line to if (&#8722;l $path or &#8722;f _) { # symbolic links or files

cg  Nov 21, 2012 
Printed
Page 158
4th code snippet, just after the sentence 'If it is neither, death awaits:'

In "Intermediate Perl", 2nd Edition, chapter 14, under the topic of "Using AUTOLOAD for Accessors", the last code snippet reads: croak "$_[0] does not understand $method\n"; If you just use the 'sub AUTOLOAD' definition from this page, the variable $method is never declared or set prior to its usage in this statement. It appears to be copied/pasted from the previous AUTOLOAD definition on page 157. Is this definition (p. 158) supposed to be part of the previous definition (p. 157)? It doesn't appear so, but I'm still learning, so wasn't sure. It could be fixed by adding the line '(my $method = $AUTOLOAD) =~ s/.*:://s;' from the previous definition.

Note from the Author or Editor:
Change the code right after the paragraph "If it is neither, death awaits" to (my $method = $AUTOLOAD) =~ s/.*:://s; # remove package name croak "$_[0] does not understand $method\n"; }

Roman Daszczyszak  Dec 31, 2009 
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  Nov 08, 2008 
PDF
Page 202
Below "The lib/Cow.pm file:"

package Cow; use parent qw(Cow); sub sound { 'neigh' } 1; ... should be ... package Cow; use parent qw(Animal); sub sound { 'moooo' } 1;

Note from the Author or Editor:
Fixed in r546857.

Jozef Reisinger  Aug 16, 2012 
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  Nov 10, 2008 
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 01, 2007
Printed
Page 223
Exercise 2

"country_code" method seems to no longer exist.

Note from the Author or Editor:
The country_code method is now the group_code method. The book was correct at the time of printing.

Lucas Marshall  Oct 07, 2009 
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  Dec 28, 2008 
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  Nov 10, 2008 
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   
Printed
Page 316
United States

2nd edition, answer to exercise 1 of chapter 4. Figure A-2, it should be "@ginger" instead of "$ginger".

Note from the Author or Editor:
In Figure A-2, there's a box with "$ginger" in it. It should be "@ginger" as noted.

Harry Pan  Sep 05, 2012 
Mobi
Page 1111
Amazon cloud reader - page/paragraph unknown

i apologize for not having error location info, but the Amazon cloud reader seems to take that away from me. It's telling me "location 616 of of 15285." In the intro chapter regarding perl modules: "To make perl look in that directory for modules..... Here's how we'd do that for the Bourne shell:" % export PERL5LIB=... The errata: that would not work on a Bourne shell. It would work in the Bourne Again and several others, but Bourne requires a separation of the export and the assignment: % PERL5LIB=... % export PERL5LIB Happy Hacking!

Note from the Author or Editor:
Noted. I should have said bash.

Stephan Beal  Jul 08, 2013