Errata

Errata for Elements of Programming with Perl will be posted here. If you discover any errors in the book, you may post them to the Author Online Forum.

When sending new errata, please include both the incorrect and the corrected text, the page number from which it came, and your contact information (name, email address, etc.) in the event that we should need to contact you.

This errata page is divided into a first section of technical errata (those involving errors in code or explanation) and a second section of much less serious typographical, formatting, and grammar corrections (many of these are very minor nits, but I catalogue them here for completeness).

A second printing of the book has corrected most of the errata listed below -- if you have the second printing then only those shown in blue should apply to your copy (they are also labelled as such).


Technical Errata:


*Page 22; 3rd para, 2nd line: (and)

*Page 63; 4th para, 3rd line:

The text states that variable names can be up to 255 characters, but the perl manpage states the limit is 251. A simple test indicates the manpage is correct. However, if you are using variable names approaching this limit I think you have other problems :-)

    longer than 255 characters).

should be:

    longer than 251 characters).

*Page 41; 3rd para, last line:

Change first instance of 'integer' to 'number':

    to get a random integer between 0 and 10

should be:

    to get a random number between 0 and 10

*Page 43; 3rd code snippet:

Missing final / on regex

    if ($response eq 'q' or $response =~ m/^\d+$) {

should be:

    if ($response eq 'q' or $response =~ m/^\d+$/) {

*Page 46; last code snippet:

Missing line break in first line of code:

    # test response if ($response eq 'q') {

should be:

    # test response 
    if ($response eq 'q') {

In 2nd printing

*Page 51; code at bottom of page:

*Page 54; 1st code snippet:

I inadvertently included the error variable ($!) in a die() statement that doesn't involve a system call.


    my $pattern = @ARGV[0] or die "no pattern given: $!";

should be:


    my $pattern = @ARGV[0] or die "no pattern given\n";

* Page 79; 2nd code snippet;

Missing $ on foo.

    foo = 12;
    print "$foo\n";

should be:

    $foo = 12;
    print "$foo\n";

*Page 106; 3rd para, last sentence

The example string lost its spacing: (single quotes below denote text in codefont).

    a string such as 'blabcfD7Kook'

should be:

    a string such as `blabcf D 7Kook'

*Page 108; 2nd line from top

Missing / at end of the regex.

    from the pattern m/a(b|c)d.

should be:

    from the pattern m/a(b|c)d/.

*Page 111; 3rd para, 6th line

    The fourth line declares

should be:

    The third line declares

in 2nd printing

*Page 118; 1st code snippet:

*Page 119; last code snippet:

There is a mathematical error in the loop that counts totals -- the total length needs to sum the word lengths multiplied by the word counts:


    $total_length += length($word);

should be:


    $total_length += length($word) * $count{$word};

*Page 143; 1st code snippet, last line

Missing semi-colon at end of line.

    $href = \%hash

should be:

    $href = \%hash;

in 2nd printing

*Page 156; top and bottom code examples

Missing line breaks: The 5th line of each example is supposed to be two lines:


    # build structure my @employees;

should be:


    # build structure
    my @employees;

And, similarly,


    # build structure my %employees;

should be:


    # build structure
    my %employees;

*Page 179; 2nd and 3rd list items (for LP info)

The noweb URL has changed locations since the book went to press, and the URL for the LP FAQ is missing a subdirectory in the path:

    http://www.cs.virginia.edu/~nr/noweb/
    http://shelob.ce.ttu.edu/daves/faq.html

These should be:

    http://www.eecs.harvard.edu/~nr/noweb/
    http://shelob.ce.ttu.edu/daves/lpfaq/faq.html

*Page 185; concept 3, line 2

Missing delimiter at end of regex:

    The pattern m/f(u|oo)bar is a

should be:

    The pattern m/f(u|oo)bar/ is a

in 2nd printing

* Page 227; first code snippet;

I inadvertently used 'unique' rather than 'uniq' in the example exec() pipeline:


    exec("sort $tmpfile | unique > $final_file");

should be:


    exec("sort $tmpfile | uniq > $final_file");

* Page 227; last code snippet;

Several things got messed up in this code snippet. Replace the whole code snippet with:

    open(DIR, 'ls |') || die "can't fork: $!";
    while (<DIR>) {
        chomp;
        print "$_" if -s $_ > 5000;
    }
    close(DIR) || die "failed $!";

* Page 228; 1st and 2nd code snippets;

Due to precedence, the final close() requires parentheses around its argument.

    close SORTED || die "problem with SORTED: $!";

    close OUT || die "problem with OUT: $!";

should be:

    close(SORTED) || die "problem with SORTED: $!";

    close(OUT) || die "problem with OUT: $!";

* Page 232; 2nd code chunk;

See also correction for page 251. The downloadable sources for the faqgrep program should be fixed soon.

    close FAQDIR;

should be:

    closedir FAQDIR;

* Page 232; 3rd code chunk;

In the open() statement, the filehandle should be uppercase:

    open(faq, "$faqdir/$faq") || die "can't $!";

should be:

    open(FAQ, "$faqdir/$faq") || die "can't $!";

in 2nd printing

*Page 237; bottom code snippet, line 4

As noted in the text, you supply a list to the 'use SomeModule' statement to import functions and symbols -- not a string containing all the symbol names as in the example:


    use SomeModule 'func1 func2';

should be:


    use SomeModule qw/func1 func2/;

* Page 251; 3rd code chunk;

    close FAQDIR;

should be:

    closedir FAQDIR;

in 2nd printing

*Page 259; code example

A prototype inadvertently was included in the transpose subroutine definition. Harmless really, but perhaps confusing because I don't go into prototypes in this book.


    sub transpose (@) {

should be:


    sub transpose {

*Page 273; 2nd codefont snippet:

Missing newline in the output showing the contents of the @INC array near the top of page: the final '.' should be on a line by itself.


*Page 283; last code snippet

    my $upper = $#_;  # length of input array

should be:

    my $upper = $#_;  # last index of input array

In 2nd printing

*Page 300; 2nd code snippet

Change 'course' to 'courses' in line 6.


    } else {
        @{$self->{course}} = @_ if @_;
    }

should be:


    } else {
        @{$self->{courses}} = @_ if @_;
    }
    

In 2nd printing

*Page 305; 1st code snippet, top line of page:


    print "popped: 9\n" if $st->pop(), "\n";

should be:


    print 'popped: ', $st->pop(), "\n";

*Page 309; 1st code snippet:

Bad method name: and 's' got prepended to the 'engueue' method name about halfway down:

    $q->senqueue(42);

should be:

    $q->enqueue(42);

*Page 312; 2nd code snippet (on one line):

In order to agree with the code at the bottom of the page to which I am referring:

    my $data = defined($_[0]) ? $_[0] : $key;

should be:

    my $data = defined($_[0]) ? shift : $key;

Typographical and other Errata:

Some of these are typos, some are grammatical fixes, and many are nitpicking -- but I want them fixed anyway


Page xii; 5th line from bottom

Misplaced hyphen.

    and object oriented-programming

should be:

    and object-oriented programming

Page xv; last line

Missing 'to'.

    when I needed rejoin the living.

should be:

    when I needed to rejoin the living.

Page xvi; 1st para, line 1

Duplicate 'uses'.

    Anyone who uses uses Perl and

should be:

    Anyone who uses Perl and

Page 7; 2nd para, 4th line

Extra 'a'.

    one could a write a program once

should be:

    one could write a program once

Page 12; 2nd para, 1st line

Inconsistent use of 'perl' instead of 'Perl'.

    utility to turn your perl program

should be:

    utility to turn your Perl program

Page 14; 5th para, 2nd sentence

    These are two standard Perl books by published by ...

should be:

    These are two standard Perl books published by ...

Page 15; sec 1.3; 2nd para, 3rd sentence:

    Insted, we

should be:

    Instead, we

Page 19; 2nd para, 4th sentence:

    because people simply writing bad code

should be:

    because people sometimes simply write bad code

Page 24; 3rd para, 2nd sentence:

Change 'Perl' to 'perl', and add missing 'a'.

    When Perl sees the # symbol

should be:

    When perl sees the # symbol

And also;

    such as string),

should be:

    such as a string),

Page 26; listing 2.1 (top of page)

An astute reader has noticed that the "comment box" above the subroutine is missing one # symbol in the 2nd column of the bottom row. Just say no to boxing or otherwise attempting to specially format comments!


Page 29; sect 2.4, 2nd para, line 7

Missing opening parenthesis, and the second 'program' should read 'module'.

    already exists in your program or one imported from another program).

should be:

    already exists in your program (or one imported from another module).

Page 30; 6th line from top

Erroneous closing parenthesis

    string context).

should be:

    string context.

Page 31; lines 1 and 2:

    declaration. Other means

should be:

    declaration (other means

Page 36; both pseudo-code snippets:

Consistency nit.

    display startup message

should be:

    display start up message

And,

    LOOP until the user quits

should be:

    LOOP until user quits

Page 39; 2nd code snippet:

    IF input is all digits or the letter q THEN set is_valid to 1
    END IF

should be:

    IF input is all digits or the letter q THEN 
        set is_valid to 1
    END IF

Page 39; last line

    in the final else block.

The 'else' there should be in codefont.


Page 43; 2nd last para:

    if the response equals q, or the

should be:

    if the response is equal to q, or the

Page 45; Sect. 3.1.4, 1st para, last sentence:

Omit 'try'.

    a plan to try test all of the

should be:

    a plan to test all of the

Page 45; Sect. 3.1.4, 2nd para:

Replace both occurrences of 'Perl' with 'perl' -- we are talking about the perl interpreter/compiler here.


Page 46;1st and 2nd paragraphs:

Replace 'Perl' with 'perl' -- all three times.


Page 49; Sect. 3.2, 1st para, line 4:

Duplicate 'section'.

    (refer to section section 1.2.3)

should be:

    (refer to section 1.2.3)

Page 49; Sect. 3.2, 2nd para, line 5:

Duplicate 'as'.

    formats such as as PostScript,

should be:

    formats such as PostScript,

Page 52; 2nd last para, last line:

Typesetting nit:

    using a logical or operator

The 'or' is in an oversized codefont, should be same size and font as the 'if' in the previous line.


Page 54; 1st code example, line 9:

Should use 'or' instead of '||' to be consistent with earlier chunk definition.

    my $pattern = $ARGV[0] || die "no pattern given: $!";

should be:

    my $pattern = $ARGV[0] or die "no pattern given: $!";

Page 55; exercise 2, line 2:

Should use 'dice' rather than 'die'.


Page 55; exercise 2, line 3:

Should use 'die' rather than 'dice'.


Page 61; 1st code snippet

Typesetting nit: Comment in third line of code is misaligned


Page 62; 4th para, 4th line:

Copy-edit nit: extra 'to'

    if you want to have to one of those symbols

should be:

    if you want to have one of those symbols

Page 62; 2nd para, last line

The word 'escape' should not be italicized here.


Page 65; 2rd para, last line

Change 'assign' to 'assigns'.


Page 65; 3rd para, 4th line

Replace first comma with colon:

    familiar with, addition, subtraction

should be:

    familiar with: addition, subtraction

Page 66; 3rd para

Replace each comma with a full stop and start a new sentence.


Page 72; 2nd para, line 2

Typesetting nit: the word 'key' should not be in code font in this sentence.


Page 72; 4th para, last line

Copy-edit nit: remove page reference from the reference to figure 4.3 (we are already on that page!).


Page 75; last code snippet

Consistency nit: missing comment in last line.

    print "@$aref\n";

should be:

    print "@$aref\n"; # prints: 11 12 13

Page 79; 2nd para, line 1

Move comma:

    In the previous chapter, we discussed simple expressions but we

should be:

    In the previous chapter we discussed simple expressions, but we

Page 79; 2nd para, last line

Add colon to end of line


Page 80; 2nd para from bottom, 1st line

    When Perl encounters

should be:

    When the perl interpreter encounters

Page 81; last line

Nit: remove final period after the parenthetical remark.


Page 84; first code example:

The final else clause got dropped down a line. It doesn't hurt anything but does make the style inconsistent.

    }
    else {
        print "$foo must be equal to $bar\n";
    }

should be:

    } else {
        print "$foo must be equal to $bar\n";
    }

Page 88; 1st new para

Missing word: 'on'.

    Note, there is some magic going in this example

should be:

    Note, there is some magic going on in this example

Page 96; 1st para, 2nd last line

Nit: extra 'if'.

    is zero and if the if block is skipped.

should be:

    is zero and the if block is skipped.

Page 99; 1st code snippet

Nit: misaligned comment.


Page 100; last para, 1st line

Nit: missing 'a'.

    than read in the first line of file.

should be:

    than read in the first line of a file.

Page 101; 2nd last para, line 1

Missing word 'in'.

    we orgranize it terms of records

should be:

    we organize it in terms of records

Page 102; 3rd line from bottom

Missing period.

    array called @ARGV Quite often,

should be:

    array called @ARGV. Quite often,

Page 103; 1st para, 3rd line from bottom

Missing 'a'.

    have list of 

should be:

    have a list of

Page 106; 1st para, line 4

Nit: missing space

    characterclass

should be:

    character class

Page 106; 2nd last para, last line

Nit: delete final parenthesis


Page 108; 3rd para from bottom

Nit: delete parenthesis.

    or subexpression optional).

should be:

    or subexpression optional.

Page 112; 3rd new para, 1st line

Missing word 'to'.

    we need clear out the hash

should be:

    we need to clear out the hash

Page 112; 4th new para, 1st line

Typesetting nit: extra space

    of Perl 's regular expressions.

should be:

    of Perl's regular expressions.

Page 127; Sect 7.2, 1st para, last sentence

Doubled phrase:

    That means that means you must

should be:

    That means you must

Page 128; 3rd new para, 2nd line

Nit: missing letter 'l' in 'real'.

    an alias for the rea variable

should be:

    an alias for the real variable

Page 129; 2nd new para, line 1

Nit: missing 'a'.

    of calling function:

should be:

    of calling a function:

Page 130; 2nd para, 3rd line

Nit: missing 'are'.

    and those that evaluated for 

should be:

    and those that are evaluate for

Page 140; exercise 2

Missing colon.

    For example

should be:

    For example:

Page 145; 2nd last para, 2nd line

Missing 'a'.

    as if it was reference.

should be:

    as if it was a reference.

Page 146; 2nd new para, 3rd line

Missing 'an'

    we split() it into array of

should be:

    we split() it into an array of

Page 148; figure 8.3

In the figure the hash is named %student -- it should be named %students.


Page 150; 1st para

Change 'Perl' to 'perl' in both instances.


Page 150; 2nd para, line 6

Missing 'it', and transposed 'the to'.

    to which is associated, not the to variable name

should be:

    to which it is associated, not to the variable name

Page 153; 1st para, line 3

Missing 'to'.

    would have been make a duplicate

should be:

    would have been to make a duplicate

Page 167; 3rd para, 2nd last line

Typo: 'useles.nw' should be 'useless.nw'.


Page 170; 1st para, lines 2-3

Missing 'a'.

    on one file at time).

should be:

    on one file at a time).

Page 173; 3rd para, 4th line

Replace 'keys' with 'whose':

    and keys values hold an array

should be:

    and whose values hold an array

Page 176; 2nd para, 6th line

Another dangling ')'.

    that chunk.)

should be:

    that chunk.

Page 179; 2nd para, 1st line

Missing 'be'.

    can found here

should be:

    can be found bere

Page 184; 2nd para, last line

Final period should be inside parentheses


Page 184; Figure 10.1

There is a missing colon after the question-mark in the second example of grouping components:

    Grouping
      ( . . . )
     (? . . . )

should be:

    Grouping
      ( . . . )
    (?:  . . . )

Page 186; 1st para, 2nd sentence

Drop second 'here' in final clause.

    performed, here we will describe it here as a

should be:

    performed, here we will describe it as a

Page 188; 1st line:

Bogus space after 'position' and prior to period.


Page 189; Sect 10.2.1; 1st para, line 2:

Missing 'at'.

    we will look an example

should be:

    we will look at an example

Page 190; last code snippet:

Final two lines of snippet missing. The following two lines should be added.

    close INPUT;
    close OUTPUT;

Page 192; 3rd line from top

Replace 'and' with 'an'.

    matching and f then zero 

should be:

    matching an f then zero

Page 192; table 10.2

Typographical nit: the vertical bar | looks too much like a lowercase l in the 2nd and last lines of the table, it should extend slightly below the line as it does in the line of text following the table.


Page 193; Sect. 10.5, first para, line 6

    and a non-word character (\W.) or between the

should be:

    and a non-word character (\W) or between th

Page 193; Sect 10.5; 2st para, line 1:

The word 'pattern' should not be in code font.


Page 196; first code snippet, line 3

A typesetting problem makes the two single quotes look more like one double quote. It is supposed to be an empty, single-quoted string. Here is the relevant line with a character by character translation just to clarify:

    $/ = '';
    dollar-slash-space-equals-space-singlequote-singlequote-semicolon

Page 198; 2nd code snippet:

Misaligned comments


Page 204; 3rd para, 4th line

It is not clear which "anchors" I am referring too here, but I meant the ^ and $ anchors.

    If you are not using these anchors in

should be:

    If you are not using the ^ and $ anchors in

Page 204; last code snippet:

Final comment misaligned.


Page 205; 2nd para, line 2:

Replace 'another' with 'the':

    Perl then finds another /x

should be:

    Perl then finds the /x

Page 207; 1st new para, line 2:

In the parentheses:

    (next, last, and redo; see chapter 5).

The 'and' should not be in code font.


Page 207; last code snippet:

At the end of the 2nd line of code:

    . ' kilometers'/e;

The second single quote should be vertical, not slanted forward.


Page 210; 2nd para, line 4:

Missing 'for'

    a better choice this type of task

should be:

    a better choice for this type of task

Page 210; middle code example:

The final curly brace, just before the __DATA__ token, should be flush to the left margin:

        print "\n";
         }
    __DATA__

should be:

        print "\n";
    }
    __DATA__

Page 217; 2nd para, line 3

Change 'to each' to 'each':.

    the $_ variable is assigned to each value

should be:

    the $_ variable is assigned each value

Page 218; 2nd para, 2nd to last line

    (remember the cmp and <=> operators).

should be:

    (see the cmp and <=> operators in the perlop manpage).

Page 227; 1st para, line 2

Remove 'there are'.

    On Unix systems there are a variety of command line

should be:

    On Unix systems a variety of command line

Page 231; last para, line 2:

    Why bother running the programming

should be:

    Why bother running the program

Page 233; exercise 1

Missing full stop at end of sentence.


Page 243; Sect 14.6, para 2, line 2:

Replace 'use' with 'uses'

    which itself use several

should be:

    which itself uses several

Page 244; last para, line 1

Missing 'to'.

    we want use for

should be:

    we want to use for

Page 253

Missing 'and'

    server -- have permission to -- 

should be:

    server -- and have permission to --

Page 253

    upload it to your server.

should be:

    upload it to your ISP's server.

in 2nd printing

Page 254; 2nd line from bottom in table 14.1

Typo


    seems to tbe only thing

should be:


    seems to be the only thing

Page 258; 1st para, line 1

Misplaced comma.

    In such a case you, may have

should be:

    In such a case, you may have

in 2nd printing

Page 262; 2nd last para

It is probably more correct to change all the semi-colons in this paragraph to commas -- and stick a colon after the word "include" in the 2nd line. I'll defer that decision to the copy-editors.


in 2nd printing

Page 262; last para

Change the first "invoke" to "start":


    You invoke the Perl debugger

should be:


    You start the Perl debugger

Page 267; 1st para, 1st sentence

Missing comma, and change 'save' to 'saved'.

    breakpoints since breakpoints are save across reloaded sessions.

should be:

    breakpoints, since breakpoints are saved across reloaded sessions.

Page 272; 1st para, line 2

Bad punctuation: change ; to , and vica-versa.

    information; to reduce complexity; and to avoid duplicate code --
    write it once, use it often.

should be:

    information, to reduce complexity, and to avoid duplicate code --
    write it once; use it often.

Page 276; 1st new para, line 3:

Remove comma:

    export it by, default we

should be:

    export it by default we

Page 290; 1st para

Change all semi-colons to commas.


Page 293; 5th para, line 1

Remove 'the'.

    look at some the terminology that is

should be:

    look at some terminology that is

Page 294; 2nd para, line 2:

Missing 'a'.

    from children's book

should be:

    from a children's book

Page 294; 2nd para, line 3:

Missing parenthesis.

    run." For those who

should be:

    run." (For those who

Page 295; 1st para, line 4:

The word 'inheritance' should not be italized here.


Page 296; 2nd para, line 2:

Replace 'Student' with 'Class' in this meta-example:

    --(Student->new('arg1', 'arg2'))--

should be:

    --(Class->new('arg1', 'arg2'))--

in 2nd printing

Page 296; 2nd para, line 6

Change "course" to "courses":


    and course key in this hash

should be:


    and courses key in this hash

in 2nd printing

Page 298; 2nd para, line 1

Spelling:


    demontrated

should be:


    demonstrated

In 2nd printing

Page 298; 2nd code snippet:

Although this is not an error, let's make the hashref more consistent with the object it is being compared to:


    my $h_ref = {name => 'Bill Jones', courses => 'English'};

should be:


    my $h_ref = {name => 'Bill Jones', courses => ['Math', 'English']};

Page 298; 3rd para, line 3:

Bad grammar:

    that also knows what class (package) it belongs.

should be:

    that also knows the class (package) to which it belongs.

Page 309; text in middle of page

Redundancy

    help differentiate different print statements

should be:

    help differentiate the print statements

Page 310; 1st para, lines 3-4

Bad hyphenation

    runt-ime

should be:

    run-time

Page 311; 2nd para, line 1

Redundancy.

    In the above description, I've only described

should be:

    In the above, I've only described

Page 316; 1st para, 1st sentence

Rewrite from 'structure'.

    structure and implement a heap class, and discuss some if it
    applications.

should be:

    structure, implementing a heap class and discussing some of its
    applications.

Page 317; 2nd para, line 4

Remove 'onto'.

    adding a new leaf onto to our binary tree.

should be:

    adding a new leaf to our binary tree.

Page 319; 1st para, line 1

'push' should not be in codefont in this context.


Page 321; last para, last line

Way too many periods.

    we also create a file. with a .std extension. containing

should be:

    we also create a file with a .std extension containing

Page 322; 1st para, line 2

Missing colon at end of sentence.


Page 323; 1st para, line 2

Move comma from after 'course' to after 'students'.


Page 332; 4th line

Missing commas.

    ...than just open read and close files and directories

should be:

    ...than just open, read, and close files and directories

in 2nd printing

Page 345; 2nd glossary entry, 4th line

Missing hyphen


    (usually non printable)

should be:


    (usually non-printable)

Page 347; variable entry

Missing 'be'.

    where data may stored and

should be:

    where data may be stored and

Page 348; Index entry


    arithmatic operators 65

should be:

    arithmetic operators 65

Many of the above errata were submitted by readers and I want to thank them for taking the time to point out errors so that other readers can benefit from their corrections and so that the quality of future printings may be improved:

Thanks!

To all, I apologize for the number of errata that found their way into the final printed version of this book. Thankfully, most errors are of the minor typographical sort, but I know that such errors can be very bothersome to the reader.