Book Image

Perl 6 Deep Dive

By : Andrew Shitov
Book Image

Perl 6 Deep Dive

By: Andrew Shitov

Overview of this book

Perl is a family of high-level, general-purpose, interpreted, dynamic programming languages consisting of Perl 5 and Perl 6. Perl 6 helps developers write concise and declarative code that is easy to maintain. This book is an end-to-end guide that will help non-Perl developers get to grips with the language and use it to solve real-world problems. Beginning with a brief introduction to Perl 6, the first module in the book will teach you how to write and execute basic programs. The second module delves into language constructs, where you will learn about the built-in data types, variables, operators, modules, subroutines, and so on available in Perl 6. Here the book also delves deeply into data manipulation (for example, strings and text files) and you will learn how to create safe and correct Perl 6 modules. You will learn to create software in Perl by following the Object Oriented Paradigm. The final module explains in detail the incredible concurrency support provided by Perl 6. Here you will also learn about regexes, functional programming, and reactive programming in Perl 6. By the end of the book, with the help of a number of examples that you can follow and immediately run, modify, and use in practice, you will be fully conversant with the benefits of Perl 6.
Table of Contents (15 chapters)

Perl 6 resources

Perl 6 has a long history and many documents were created during that time, for instance, language ideas, draft specifications, and compiler documentation. Many enthusiasts wrote articles and blog posts about Perl 6. Some of that is outdated and does not reflect the current state of the language. In this chapter, I will give you a brief list of materials that are up-to-date and that you should use in your practice of working with Perl 6.


The main entry point for documentation of the Perl 6 programming language is the Documentation section of Perl 6's site ( It contains a few sections with a comprehensive description of the types, operators, and built-in classes that are available in Perl 6. As the language is still developing, you may sometimes find places in the documentation where it does not reflect the current state of the language. In this case, you may consult the community of language developers or check the files from the test suite.

Test Suite

Perl 6's test suite, called Roast, can be found in the repository at It contains thousands of tests covering many corners of Perl 6. The test suite is also a good place to look if you want to see ways you can write programs in Perl 6. It may be a long read sometimes, but many tests are checking the features from all possible angles.

In Roast, the tests are grouped in directories with names such as S32-io. These names correspond to the numbers of the Synopses, and are split into thematic sections. For example, for the Synopses 11 'Compilation Units', there exist three directories in testsS11-compunits, S11-modules, and S11-repository. is a huge file describing the formal Perl 6 grammar. The grammar of Perl 6 is written in Perl 6 itself. The repository of contains the grammar and the viv utility that translates the grammar into the Perl 5 code. We have mentioned the grammar because it may be interesting for those readers who want to dig deeper into the internal structure of the grammar. In the rest of this book, we will explain the grammar based on examples of code in Perl 6.


The developers of Perl 6 traditionally use IRC for communication. You may also join the #perl6 channel to ask questions about the language or execute a piece of Perl 6 online.

To join the channel, follow the instructions listed on the page.

If you want to run the code in IRC, refer to the rakudo bot as follows:

<me> rakudo: say "Hello, World!"
<+camelia> rakudo-moar cb8fa0: OUTPUT: «Hello, World!␤»

In the output, you can see that Rakudo is using the MoarVM backend by default. The string that was printed by the program is displayed after the OUTPUT keyword.

Use this feature carefully as the result of your requests will be visible to the whole room and also be logged. The best use case is to show the behavior of the compiler when you find a bug or when you see a different result from what is said in the documentation. The Perl 6 developers are always present in the IRC channel and will advise on what is wrong or will aim to fix the bug and make the documentation correct.

If you are on Facebook, visit the Perl 6 group here:

In the offline, you will see many people who love Perl 6 at various conferences. Go to the Perl Conference (previously known as YAPC, (Yet Another Perl Conference)), which is held every year in Europe and in the USA. You may find more about them on and For many years, there were work Perl booths at the big open-source conferences like OSCON and FOSDEM. There are also many local conferences, workshops, and local group meetings. Find the closest group to your location at