Errata

Learning Perl 6

Errata for Learning Perl 6

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
PDF
Page xvi
1st paragraph

the package name is not rakudo-star

should have been

C:\ choco install rakudostar

instead.

Note from the Author or Editor:
Change as noted

hkdtam  Oct 16, 2018  Mar 13, 2020
PDF
Page 8
third code section

There are two code sections that look like this:

put 'Hello Perl 6!';
put 'The time is ', now;

In the second one, remove the final semicolon:

put 'Hello Perl 6!';
put 'The time is ', now

Note from the Author or Editor:
Change as noted

brian d foy  Sep 18, 2018  Mar 13, 2020
Printed
Page 8
last code example

On p8 the bottom example:

loop { state $count = 0; sleep 1; print $count, "\r"; }

is it perhaps missing a ++? as in:

loop { state $count = 0; sleep 1; print $count++, "\r"; }

It just seems a little pointless without the ++.

Note from the Author or Editor:
Change as noted

Anonymous  Oct 09, 2018  Mar 13, 2020
Printed
Page 12
2nd paragraph

"You must start your name with a letter or digit"

raku.guide indicates letter or underscore, not digit.

Note from the Author or Editor:
Change as noted

David White  Feb 19, 2021 
Printed
Page 14
bottom of page

p6doc language/variables gives No such type 'language/variables'

but

p6doc variables seems to give the desired documentation page

Note from the Author or Editor:
Change as noted

Jason Lewis  Oct 07, 2018  Mar 13, 2020
Printed
Page 16
1st paragraph

The env command is usually available under /usr/bin/env. Only some systems provide /bin/env in addition to /usr/bin/env.

Note from the Author or Editor:
substitute /usr/bin/env for /bin/env as noted

Andreas Vögele  Jan 10, 2020  Mar 13, 2020
Printed
Page 24
first paragraph

Page 24, first paragraph, states, "In the previous exercise, you couldn't specify a hexadecimal number as an argument." My solution to Exercise 2.6 works fine with hexadecimal arguments:

2018-09-27 20:57:27 dpchrist@vstretch ~/src/learningperl6
$ cat /etc/debian_version
9.5

2018-09-27 20:57:38 dpchrist@vstretch ~/src/learningperl6
$ uname -a
Linux vstretch 4.9.0-8-amd64 #1 SMP Debian 4.9.110-3+deb9u4 (2018-08-21) x86_64 GNU/Linux

2018-09-27 20:57:47 dpchrist@vstretch ~/src/learningperl6
$ perl6 -v
This is Rakudo version 2016.12 built on MoarVM version 2016.12
implementing Perl 6.c.

2018-09-27 20:57:52 dpchrist@vstretch ~/src/learningperl6
$ head -n 12 ex-2.6.p6
#!/usr/bin/env perl6
# $Id: ex-2.6.p6,v 1.2 2018/09/28 03:50:10 dpchrist Exp $
# Per brain d foy, 2018, "Learning Perl 6".
# Copyright 2018 by David Paul Christensen dpchrist@holgerdanske.com
# Public Domain.

sub MAIN ( $number ) {
put 'binary : ', $number.base: 2;
put 'octal : ', $number.base: 8;
put 'decimal : ', $number.base: 10;
put 'hexadeciaml: ', $number.base: 16;
}

2018-09-27 20:57:57 dpchrist@vstretch ~/src/learningperl6
$ perl6 ex-2.6.p6 0xDEADBEEF
binary : 11011110101011011011111011101111
octal : 33653337357
decimal : 3735928559
hexadeciaml: DEADBEEF

Note from the Author or Editor:
This seems to be true, but it's a bigger fix than we can accommodate in a reprint.

David Christensen  Sep 27, 2018  Mar 13, 2020
PDF, ePub, Mobi
Page 28
2nd and 3rd paragraph

The phrase "For numbers, 0 is False and everything else is True" appears at the end of the second paragraph, and is repeated at the end of the third.

This phrase should only appear once.

Note from the Author or Editor:
Remove the sentence from the second paragraph.

José Joaquín Atria  Sep 07, 2018  Mar 13, 2020
Printed
Page 32
Chapter 2, Section "Chained comparisons"

The variable $n needs to be declared with "my".

% perl6
> $n = 10
10
> 7 < $n < 15

ought to be changed to

% perl6
> my $n = 10
10
> 7 < $n < 15

Note from the Author or Editor:
Change as noted.

Andreas Vögele  Nov 20, 2018  Mar 13, 2020
PDF, ePub
Page 34
4th code example

Chapter 2, Section "Conditional Branching" (page 34 on the PDF)

There's an operator precedence problem on:

Some people prefer an if with a negated condition:

if ! $number %% 2 {
put 'The number is odd';
}

Should be either one of:

if ! ( $number %% 2 ) {...}
if not $number %% 2 {...}

Note from the Author or Editor:
Change to

if ! ( $number %% 2 ) {...}

Lucas Buchala  Sep 11, 2018  Mar 13, 2020
PDF, ePub, Mobi
Page 41
3rd code snippet

In the snippet

my Int $number;
put $number2.^name; # Int

the first and the second variable names are different.

They should be the same.

Note from the Author or Editor:
change the second variable name to match the first ($number)

José Joaquín Atria  Sep 07, 2018  Mar 13, 2020
Printed
Page 45
3rd paragraph code example

put .numerator, '/', .denominator, ' = ' given $sum;

is missing the final printout of $sum

maybe should be something like:

put .numerator, '/', .denominator, ' = ', $sum given $sum;

Note from the Author or Editor:
Change as noted

Jason Lewis  Oct 10, 2018  Mar 13, 2020
PDF
Page 47
4th code example

I found a typo at the bottom of page 47: It says

% perl6
> i*i
-1

But if you multiply i*i, you get a Complex number back. You need to coerce it with .Int to get -1:

% perl6
> i*i
-1+0i
> (i*i).Int
-1

Note from the Author or Editor:
Change output to:

> i*i
-1+0i

Packy Anderson  Sep 03, 2018  Mar 13, 2020
PDF
Page 54
7th line of 1st code sample

The book says:

> Q :q 「This quote \「\」 escapes」
This quote 「 escapes

But it should be:

> Q :q 「This quote \「\」 escapes」
This quote 「」 escapes

Note from the Author or Editor:
Change as noted

Packy Anderson  Sep 03, 2018  Mar 13, 2020
PDF
Page 55
7th code sample

put 'hamadryas PERLICUS'.tc;

should be

put 'hamadryas PERLICUS'.tclc;

Note from the Author or Editor:
Change as noted.

Packy Anderson  Sep 03, 2018  Mar 13, 2020
Printed
Page 56
Line -13

Result is True, not False ( 'Hama...'.fc.starts-with: 'hama' )

Note from the Author or Editor:
In second code example from bottom, change to:

> 'Hamadryas perlicus'.fc.starts-with: 'hama'
True

Luc St-Louis  Oct 01, 2018  Mar 13, 2020
PDF
Page 60
3rd line of 6th code sample

using the code

if $answer { 'You chose <', $answer, '>' }

has an interesting side effect. It looks like

put do { 'You chose <', $answer, '>' }

puts a single space between the arguments:

> $answer = ' X '.trim;
X
> put do { 'You chose <', $answer, '>' }
You chose < X >
> put 'You chose <', $answer, '>'
You chose <X>

This makes it look (erroneously) like .trim compresses leading and trailing spaces down to single spaces, not removing them entirely, and yielding the following output when the script is modified to use .trim:

% perl6 prompt.p6
What's your favorite animal? Butterfly
You chose < Butterfly >

An easy way to fix this would be to concatenate them using ~, thus changing the 3rd line of the script to

if $answer { 'You chose <' ~ $answer ~ '>' }

This way, when the program is changed to use .trim, you get the following result:

% perl6 prompt.p6
What's your favorite animal? Butterfly
You chose <Butterfly>

Note from the Author or Editor:
Changed as noted

Packy Anderson  Sep 03, 2018  Mar 13, 2020
Printed
Page 90
Top half

The warning "You cannot make an empty List with $(): that's just Nil" only applies to version 6.c of the Raku programming language. From Rakudo 2018.10 on $() hasn't got any special meaning and makes an empty list (unless "use v6.c" is effective).

Note from the Author or Editor:
Remove the warning box on page 90.

Andreas Vögele  Jan 10, 2020  Mar 13, 2020
Printed
Page 90
Last paragraph

The "put" in the below example ought to be replaced with "say" like on page 105. Otherwise the error message "Use of uninitialized value $ of type Any in string context" is output.

my $butterflies = ( $, 'Sostrata', 'Junonia' );
put $butterflies; # ((Any) Sostrata Junonia)

Note from the Author or Editor:
Change

put $butterflies; # ((Any) Sostrata Junonia)

to

say $butterflies; # ((Any) Sostrata Junonia)

Andreas Vögele  Jan 10, 2020  Mar 13, 2020
Printed
Page 95
First example

William Michels already pointed out that the below example does no longer limit the input to 17 lines. Instead "Got line 17" is output.

for lines(17) {
put "Got line $_";
}

I'm wondering whether there's a bug in recent Rakudo releases. The below code works as expected.

for $*IN.lines(17) {
put "Got line $_";
}

Note from the Author or Editor:
Remove the paragraph that starts "You need those parentheses", and remove the code example that follow it. The page picks up with "You can break"

Andreas Vögele  Jan 10, 2020  Mar 13, 2020
PDF
Page 99
2nd line of 2nd code sample

The second code sample reads

my $countdown = <1 2 3 4 5>.reverse.eager;
put $countdown.^name; # Seq
put $countdown.elems; # 5

It should read

my $countdown = <1 2 3 4 5>.reverse.eager;
put $countdown.^name; # List
put $countdown.elems; # 5

Note from the Author or Editor:
Change as noted

Packy Anderson  Sep 03, 2018  Mar 13, 2020
PDF
Page 103
Second to last

Some spacing needed in "[POSITION]is a postcircumfix..."

Note from the Author or Editor:
Change as noted

Ukar  Mar 14, 2019  Mar 13, 2020
PDF
Page 109
Second to last

In the sentence "It takes a starting index, a length, and the items to remove from the list." about .splice, doesn't the last parameter in .splice specify the items with which to replace the removed elements? From the doc:

multi method splice(Array:D: $start = 0, $elems?, *@replacement --> Array)

Deletes $elems elements starting from index $start from the Array, returns them and replaces them by @replacement.

Note from the Author or Editor:
change "remove from list" to "add to list"

Ukar  Mar 14, 2019  Mar 13, 2020
Page 109
5th example

The example of unshift here:

my @butterfly-genus = Empty;
@butterfly-genus.unshift: <Hamadryas Sostrata>;
say @butterfly-genus; # [Hamadryas Sostrata]

... indicates that the list items were added as two unique items, but this would actually result in the list being added as a single array item like so:

@butterfly-genus.unshift: <Hamadryas Sostrata>; # [(Hamadryas Sostrata)]
say @butterfly-genus; # [Hamadryas Sostrata]
[(Hamadryas Sostrata)]

following from that, the next example would look like this:

@butterfly-genus.push: <Junonia>;
say @butterfly-genus; # [(Hamadryas Sostrata) Junonia]

Note from the Author or Editor:
Change as noted.

Likely this is the result of the latest versions doing things differently, but I haven't verified that.

Tim Howe  Jan 12, 2022 
PDF
Page 111
Fourth code sample

The code sample reads:

my $list = ( 1; 'Hamadryas'; 'a', 'b' );
put $list.elems; # 3
say $list; # (1 2 (a b))
put $list.[0].^name; # Int
put $list.[1].^name; # Str
put $list.[*-1].^name; # List

It should read:

my $list = ( 1; 'Hamadryas'; 'a', 'b' );
put $list.elems; # 3
say $list; # (1 Hamadryas (a b))
put $list.[0].^name; # Int
put $list.[1].^name; # Str
put $list.[*-1].^name; # List

Note from the Author or Editor:
Change as noted

Patrick Anderson  Sep 08, 2018  Mar 13, 2020
PDF, ePub, Mobi
Page 114
4th paragraph and code snippet

The page says:

Each sublist has three elements:

((1 a ????)(2 b ????)(3 ????))

but the last sublist only shows two. It should say

Each sublist has three elements:

((1 a ????)(2 b ????)(3 c ????))

Note from the Author or Editor:
Change as noted.

José Joaquín Atria  Sep 07, 2018  Mar 13, 2020
PDF
Page 117
Eighth (final) code sample

The code sample reads

my $allomorphs = <137 2i 3/4 a b>;
my $int-strs = $allomorphs.grep: IntStr; # (137)
my $rat-strs = $allomorphs.grep: RatStr; # (3/4)
my $img-strs = $allomorphs.grep: ComplexStr; # (2i)
my $strs = $allomorphs.grep: Str; # (a b)

But it should read

my $allomorphs = <137 2i 3/4 a b>;
my $int-strs = $allomorphs.grep: IntStr; # (137)
my $rat-strs = $allomorphs.grep: RatStr; # (3/4)
my $img-strs = $allomorphs.grep: ComplexStr; # (2i)
my $strs = $allomorphs.grep: Str; # (137 2i 3/4 a b)

Note from the Author or Editor:
change as noted.

Packy Anderson  Sep 08, 2018  Mar 13, 2020
PDF
Page 119
First paragraph, second code sample

You can use these methods together. This selects the even numbers then squares them:

my $squares = $allomorphs
.grep( { ! .does(Numeric) } )
.map( { $_ %% 2 ?? $_**2 !! |() } );

I have no idea what this is trying to accomplish. Considering that the last example that mentioned $allomorphs made its value the List (137 2i 3/4 a b), trying to run the code above yields:

Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏a' (indicated by ⏏)

This is because the List $allomorphs is transformed by the .grep into the list ( a b ), and the .map then attempts to square the values 'a' and 'b'.

I understand that it's trying to combine .grep and .map, but it's not doing so in any way that makes sense.

Note from the Author or Editor:
Change code example to:


my $squares = (0..9)
.grep( { $_ %% 2 } )
.map( { $_**2 } );

Packy Anderson  Sep 08, 2018  Mar 13, 2020
PDF
Page 124
1st paragraph

"What’s actually in $result?"

should read

"What’s actually in $value?"

Note from the Author or Editor:
Change as noted

Packy Anderson  Sep 08, 2018  Mar 13, 2020
Printed
Page 131
try/CATCH code example

Misindented.

Note from the Author or Editor:
Indent like so:


Indent like so, with everything inside the try { ... } moved over four spaces:

try {
CATCH {
when X::MyException { put 'Caught a custom error' }
}
my-own-error();
}

Luc St-Louis  Oct 08, 2018  Mar 13, 2020
PDF
Page 132
First code snippet

The snippet says

my $result = do-something();
if $result { ... }
my $did-it-work = ?$results;

but it should probably say

my $result = do-something();
if $result { ... }
my $did-it-work = ?$result;

Note from the Author or Editor:
change as noted

José Joaquín Atria  Sep 21, 2018  Mar 13, 2020
PDF
Page 135
Second to last paragraph

The sentence "You can more than one level at a time." seems to be missing some details.

Note from the Author or Editor:
Change the first two sentences of the second to last paragraph to:

To build a deeper path, use .add, which allows you to add more than one level at a time.

Ukar  Mar 15, 2019  Mar 13, 2020
PDF
Page 139
5th (last) Paragraph

"It’s probably easiest to represent it as a decimal number"

should read

"It’s probably easiest to represent it as an octal number"

Note from the Author or Editor:
Change as noted

Packy Anderson  Sep 09, 2018  Mar 13, 2020
Printed
Page 139
Line 10

Misplaced comma in "write, this".

Note from the Author or Editor:
should be "as I write this," in note

Luc St-Louis  Oct 01, 2018  Mar 13, 2020
Other Digital Version
153
1st code section, 2nd line

The comment reads:

# ((Any) perlicus Sostrata Junonia)

However, 'perlicus' should be removed:

# ((Any) Sostrata Junonia)

Note from the Author or Editor:
This is actually on page 105 (Chapter 6, "Changing a Single Element")

the third to last code block should read:

my $butterflies = ( $, 'Sostrata', 'Junonia' );
say $butterflies; # ((Any) Sostrata Junonia)

Nova Patch  Oct 10, 2018  Mar 13, 2020
PDF
Page 156
First code snippet in the page

In the code snippet:

my Buf $buffer = $fh->read( $count );

the pointy block arrow (->) is used to invoke the `read` method. However, a dot (.) should be used instead.

Note from the Author or Editor:
Change

my Buf $buffer = $fh->read( $count );

to


my Buf $buffer = $fh.read( $count );

Ukar  Apr 01, 2019  Mar 13, 2020
PDF
Page 160
the code below "The .pop method removes the last item:"

my $first-item = @butterfly-genus.pop;
say @butterfly-genus; # [Hamadryas Sostrata]
say $first-item; # Junonia

---
$first-item

should be ...

$last-item

Note from the Author or Editor:
Change uses of $first-item to $last-item in that example.

Anonymous  Nov 11, 2019  Mar 13, 2020
Printed
Page 164
Code example at bottom of page (and following page)

The variable names read better as @permissible... instead of @permissable...

Note from the Author or Editor:
Change all instances of @permissable to @permissible

Luc St-Louis  Oct 01, 2018  Mar 13, 2020
Printed
Page 166
Line -10 and following

%color should be %color-name-to-rgb.

Note from the Author or Editor:
Change all instances of %color on that page to %color-name-to-rgb

Luc St-Louis  Oct 01, 2018  Mar 13, 2020
PDF
Page 195
1st code example

multi subsomething ( $a ) { put "One argument"; }
multi subsomething ( $a, $b ) { put "Two arguments"; }

should read

multi sub something ( $a ) { put "One argument"; }
multi sub something ( $a, $b ) { put "Two arguments"; }

Note from the Author or Editor:
change as noted

Packy Anderson  Sep 15, 2018  Mar 13, 2020
ePub
Page 203
First sentence

The example on the previous page is:
"You call .reverse on a List to flip the list around. When you call List methods it just works:
my $countdown = <1 2 3 4 5>.reverse;
put $countdown.^name; # Seq
put $countdown.elems; # 5”

On the next page the first line is "The result isn’t actually a Seq, but in most common cases that isn’t important."
I think it should say that the result *IS* actually a Seq.

Note from the Author or Editor:
Change to read "The result is actually a Seq"

N. Dogger  Sep 08, 2018  Mar 13, 2020
Printed
Page 304
Line 3

The '+' should be a '*'.

Note from the Author or Editor:
Change as noted to "3 * 3"

Luc St-Louis  Oct 01, 2018  Mar 13, 2020
Printed
Page 324
Top three code examples

Missing comma after $filename (three instances).

Note from the Author or Editor:
The first three examples have the line

'/bin/some_command', '-n', '-t', $filename

Change those by adding a comma to the end:

'/bin/some_command', '-n', '-t', $filename,

Luc St-Louis  Oct 17, 2018  Mar 13, 2020
PDF
Page 332
Second to last

operaters -> operators

Ukar  Mar 16, 2019  Mar 13, 2020
PDF
Page 361
Paragraph 6

The current sentence is "This like your basic number-guessing program, but you have to make two sets of comparisons."

It should probably be "This is like your basic number-guessing program, but you have to make two sets of comparisons." The word "is" should be added after the word "This".

Note from the Author or Editor:
Change as noted.

Amir Aharoni  Sep 04, 2018  Mar 13, 2020
Other Digital Version
596
Location 596 (Kindle)

sub MAIN ( $thingy1, $thingy2 ) { put '1: ', $thingy1; put '2: ', $thingy1; }

You probably intended:

sub MAIN ( $thingy1, $thingy2 ) { put '1: ', $thingy1; put '2: ', $thingy2; }

Note from the Author or Editor:
Change as noted

Mark Devine  Sep 04, 2018  Mar 13, 2020
ePub
Page 1582
2nd paragraph (Location 1582 Kindle)

*** In the original:

If that’s too restrictive you can set the PATH to exactly the directories that you consider safe:

%*ENV<PATH> = '/bin:/sbin';
print Q :x 'hostname'; # does not find this
print Q :x '/bin/hostname'; # this works


*** Both actually work. Perhaps change the %*ENV<PATH> to make the demonstration valid.


If that’s too restrictive you can set the PATH to exactly the directories that you consider safe:

%*ENV<PATH> = '/sbin:/usr/local/bin';
print Q :x 'hostname'; # does not find this
print Q :x '/bin/hostname'; # this works

Note from the Author or Editor:
change as noted:

%*ENV<PATH> = '/sbin:/usr/local/bin';

Mark Devine  Sep 07, 2018  Mar 13, 2020
ePub
Page 1987
Middle of page (Location 1987 Kindle)

Subset::Common

*** should be

Subsets::Common

Note from the Author or Editor:
Change as noted

Mark Devine  Sep 07, 2018  Mar 13, 2020