This HTML version of Think Perl 6 is provided for convenience, but it is not the best format of the book. You might prefer to read the PDF version.

Think Perl 6: How to Think Like a Computer Scientist

Laurent Rosenfeld, with Allen B. Downey

1st Edition, Version 0.5.0

May 2017

Part I
Starting with the Basics

This book has been divided in two parts. The main reason for that is that I wanted to make a distinction between on the one hand relatively basic notions that are really needed for any programmer using Perl 6, and on the other hand more advanced concepts that a good programmer needs to know but may be less often needed in the day-to-day development work.

The first eleven chapters (a bit more than 200 pages) which make up this first part are meant to teach the concepts that every programmer should know: variables, expressions, statements, functions, conditionals, recursion, operator precedence, loops, etc., as well as the basic data structures commonly used, and the most useful algorithms. These chapters can, I believe, be the basis for a one-semester introductory course on programming.

Of course, the professor or teacher that wishes to use this material is entirely free to skip some details from this Part 1 (and also to include sections from Part 2), but, at least, I have provided some guidelines on how I think this book could be used to teach programming using the Perl 6 language.

The second part focuses on different programming paradigms and more advanced programming techniques that are in my opinion of paramount importance, but should probably studied in the context of a second, more advanced, semester.

For now, let’s get down to the basics. It is my hope that you will enjoy the trip.

Part II
Moving Forward

Now that you have reached the end of the first part of this book, you should non longer be a pure beginner. By now, you should be able to go through the official Perl 6 documentation ( and find your way.

There are many more things to say about programming. The next three chapters will be devoted to more advanced concepts and new programming paradigms, including:

Object-oriented programming
We will describe how we can construct our own types and methods, which is a way to extend the language.
Using grammars
This is a form of declarative programming in which you define axioms and rules and derive knowledge from these; grammars are a very powerful way to analyze textual content and are used to transform program source code into executable statements.
Functional programming
This is yet another programming paradigm in which computation is expressed as the evaluation of mathematical functions.

Each of these chapters probably deserves a full book in its own right (and might have one some day), but we hope to tell you enough about them to get you going. In my opinion, every programmer should know about these powerful concepts in order to be able to select the best way to solve a given problem.

Perl 6 is a multiparadigm language, so we can really cover these topics in terms of the Perl 6 language. A number of subjects that we have introduced in previous chapters should lead you easily into these new ideas, and this is the reason why I think it is possible to properly cover them with just one chapter for each of these subjects.

There will be far fewer exercises in the second part, because we expect you by now to be able to think up your own exercises and make your own experiments for yourself. And there will be only very few suggested solutions, because we are getting at a level where there is really not one right solution, but many possible ways to tackle a problem.

Concerning the Perl language, we have covered a lot of material, but, as I warned from the very beginning, this is far from exhaustive. The following are among the topics that we have not covered (and will not cover); you might want to explore the documentation on them yourself:

Concurrent programming
Today’s computers have multiple processors or multicore processors; Perl 6 offers various ways of taking advantage of these to run computing processes in parallel in order to improve performance and reduce run time; see for more details.
Exception handling
Managing situations where something goes wrong is an important part of programming. Perl 6 offers various mechanisms to handle such situations. See for more details.
Interprocess communication:
Programs often have to run other programs and to communicate with them. See
How to create, use, and distribute Perl 6 modules. See
Native calling interface
How to call libraries that are written in other programming languages and follow the C calling conventions. See

Are you using one of our books in a class?

We'd like to know about it. Please consider filling out this short survey.

Think DSP

Think Java

Think Bayes

Think Python 2e

Think Stats 2e

Think Complexity

This document was translated from LATEX by HEVEA.