Mastering Perl by brian d foy This errata page lists errors outstanding in the most recent printing. If you have technical questions or error reports, you can send them to booktech@oreilly.com. Please specify the printing date of your copy. This page was updated March 21, 2008. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification Confirmed errors: (7) 2nd paragraph; In fifth sentence, "firstF" should be "first". {10} line 12; That code should have the $i replaced with 0: print "\t\t\$&: ", substr( $_, $-[0], $+[0] - $-[0] ), "\n"; {13} 2nd paragraph; My problem is precedence. The alternation is higher precedence than sequence, Should be: My problem is precedence. The alternation is lower precedence than sequence, {19} code snippet continued from page 18; The $type and $found variables are declared but never used. Remove the line of code: my( $type, $found ); (24) 2nd paragraph; "The positive lookbehind assertion also looks backward, but its pattern must not match. Should read "but its pattern must match." {25} second code example on page; The line: $money =~ s/(?<=\d)(?=(?:\d\d\d)+$)/,/g; # $1,234.5,678 This is the code right after the line "but I still have that extra comma", and should read: $money = '$1234.5678'; $money =~ s/(?<=\d)(?=(?:\d\d\d)+\b)/,/g; # $1,234.5,678 [28] 2nd paragraph in section "Final Thoughts"; Replace the 2nd paragraph and following bit with: I don't have to be content with the simple character classes such as \w (word characters), \d (digits), and the others denoted by slash sequences. I can also use the POSIX character classes. I enclose those in the square brackets with colons on both sides of the name, and then put them in a character class (so, two sets of square braces): print "Found alphabetic character!\n" if $string =~ m/[[:alpha:]]/; print "Found hex digit!\n" if $string =~ m/[[:xdigit:]]/; I negate those with a caret, ^, after the first colon: print "Didn't find alphabetic characters!\n" if $string =~ m/[[:^alpha:]]/; print "Didn't find spaces!\n" if $string =~ m/[[:^space:]]/; (31) 3rd paragraph of non-code text; It appears a word is missing in the 4th sentence: "... I've seen people do such as using ..." should probably be "... I've seen people do such things as using ..." (36) Second code example under "Tainted Data" section; Example reads: $ perl tainted-args.pl Argument [foo] is tainted but it's missing the argument "foo". The example should read: $ perl tainted-args.pl foo Argument [foo] is tainted {95} First code example; As written this example will produce very unexpected results. The line: $diff = timediff( $t1, $t0 ); should be written: $diff = timediff( $end, $start ); {119} First full sentence; "Lower numbers are more severe, with 5 being the least severe:" should be: "Higher numbers are more severe, with 5 being the most severe problems:" {129} Code in last section; %dict = { 1 => 'one'}; should read %dict = ( 1 => 'one' ); {139} code block; The paragraph before the code example states: "I also label the loop REPL ..." But the while loop has no label. It should be: My processing loop stays the same even if I add more operators. I also label the loop REPL (for Read-Evaluate-Print), and I'll use that label later when I want to control the looping from one of my subroutines: #!/usr/bin/perl use strict; use vars qw( %Operators ); %Operators = ( '+' => sub { $_[0] + $_[1] }, '-' => sub { $_[0] - $_[1] }, '*' => sub { $_[0] * $_[1] }, '/' => sub { $_[1] ? eval { $_[0] / $_[1] } : 'NaN' }, ); REPL: while( 1 ) { my( $operator, @operand ) = get_line(); my $some_sub = $Operators{ $operator }; unless( defined $some_sub ) { print "Unknown operator [$operator]\n"; last REPL; } print $Operators{ $operator }->( @operand ); } print "Done, exiting...\n"; sub get_line { print "\nprompt> "; my $line = ; $line =~ s/^\s+|\s+$//g; ( split /\s+/, $line )[1,0,2]; } (182) Last sentence of first paragraph, first sentence of 2nd paragraph; "If I give the switch the wrong sort of value, for instance, a string where I wanted a number, GetOptions doesn't set a value (so it doesn't turn a string into the number 0, for instance): # code block If I give the switch the wrong sort of value, for instance, a string where I wanted a number, GetOptions doesn't set a value." I see a couple of issues here: 1) One sentence is repeated in both paragraphs ("If I give...a value.") 2) "for instance" is used twice in the first sentence. {204} Last paragraph, first sentence; Instead of: In this short program I simply give die an anonymous array. The sentence should be: In this short program I simply give die an anonymous hash. {215} Last line of root-logger.conf code; log4perl.appender.myFILE.layout.ConversionPattern = [%c] (%F line %L) %m%n should be: log4perl.appender.myFILE.layout.ConversionPattern = [%p] (%F line %L) %m%n {231} in sub show_arrays(); In the following subroutine sub show_arrays { foreach my $ref ( @_ ) { >> print "Element [1,1] is $AoA->[1][1]\n"; } } print line should be: >> print "Element [1,1] is $ref->[1][1]\n"; {270} top of page; Remove this text at the end of that section. The PerlIO::scalar is the right module, but it loads XS stuff so it's not right for talking about Perl-level tie stuff. "You might already use tied variables without knowing it. In Chapter 5 of T, we talked about opening a filehandle to a scalar reference: open my($fh), ">", \$print_to_this_string or die "Could not open string: $!"; Once I have the filehandle, I do filehandle sorts of things with it. How does it perform the magic? The M module implements a tied filehandle and takes responsibility for the filehandle behavior. It can do whatever it likes, in this case printing to a scalar instead of a file." (274) 2nd full paragraph; The second sentence of this paragraph says: "... but with an the object form I can." ^^ Remove "an". {275} Last paragraph; Change the last paragraph on that page to: From the output I can see that I start off with the value 1 in $number, but when I try to assign -5 (a value with a magnitude greater than 3), it doesn't work and the value is still 1. Normally my program would croak right there, but I used an eval to catch that error. The same thing happens for -4. When I try -3, it works: (281) First paragraph under "Something a Bit More Realistic"; "... I have six possibilities." should read "... I have five possibilities."