Learning Perl 6

Book description

f you’re ready to get started with Raku (formerly Perl 6), this is the book you want, whether you’re a programmer, system administrator, or web hacker. Raku is a new language—a modern reinvention of Perl suitable for almost any task, from short fixes to complete web applications. This hands-on tutorial gets you started.

Author brian d foy (Mastering Perl) provides a sophisticated introduction to this new programming language. Each chapter in this guide contains exercises to help you practice what you learn as you learn it. Other books may teach you to program in Raku, but this book will turn you into a Raku programmer.

Learn how to work with:

  • Numbers, strings, blocks, and positionals
  • Files and directories and input/output
  • Associatives, subroutines, classes, and roles
  • Junctions and sets
  • Regular expressions and built-in grammars
  • Concurrency features: Promises, supplies, and channels
  • Controlling external programs and other advanced features

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. The Backstory of Perl 6
    2. What You Should Already Know
    3. Getting Rakudo
    4. How to Use This Book
    5. How to Get Help
    6. Conventions Used in This Book
    7. Using Code Examples
    8. O’Reilly Safari
    9. How to Contact Us
    10. Acknowledgments
  2. 1. Introduction
    1. Why Perl 6?
    2. First Steps with the REPL
    3. Reading the Documentation
    4. Basic Syntax
      1. Terms
      2. Operators and Expressions
      3. Statements
      4. Blocks
      5. Comments
      6. Unspace
      7. Objects and Classes
    5. Variables
      1. Simple Output
      2. Lexical Scope
      3. Predefined Variables
    6. Making and Running a Program
    7. Summary
  3. 2. Number Guessing
    1. Binding and Assignment
    2. A MAIN Program
      1. Program Arguments
      2. Prompting for Values
    3. Literal Numbers
      1. Formatting Numbers
    4. Numeric Operations
    5. Conditional Execution
      1. Boolean Values
      2. Comparing Things
      3. Conditional Branching
    6. Putting It All Together
    7. Summary
  4. 3. Numbers
    1. Number Types
    2. Integers
      1. Type Constraints
      2. Smart Matching
    3. Rational Numbers
    4. Imaginary and Complex Numbers
    5. Numbers Small and Large
    6. The Numeric Hierarchy
    7. Summary
  5. 4. Strings
    1. Literal Quoting
    2. Escaped Strings
      1. Adverbs for Quoting
      2. String Operators and Methods
      3. Looking Inside Strings
      4. Normal Form Grapheme
      5. String Comparisons
      6. Prompting for Input
      7. Number to String Conversions
      8. String to Number Conversions
    3. Interpolated Strings
    4. Here Docs
    5. Shell Strings
      1. Shell Safety
    6. Fancier Quoting
    7. Summary
  6. 5. Building Blocks
    1. Blocks
      1. Lexical Scope
      2. Control Structures
      3. Phasers
      4. Storing Blocks
      5. Blocks with Parameters
    2. Simple Subroutines
      1. Named Subroutines
    3. Whatever Code
      1. Subsets
    4. Summary
  7. 6. Positionals
    1. Constructing a List
      1. Iterating All the Elements
    2. Ranges
      1. The @ Coercer
    3. Sequences
      1. Infinite Lazy Lists
      2. Gathering Values
    4. Single-Element Access
      1. Changing a Single Element
      2. Multiple-Element Access
    5. Arrays
      1. Constructing an Array
      2. Interpolating Arrays
      3. Array Operations
      4. Lists of Lists
      5. Flattening Lists
      6. Interesting Sublists
    6. Combining Lists
      1. The Zip Operator, Z
      2. The Cross Operator, X
      3. The Hyperoperators
      4. The Reduction Operator
    7. Filtering Lists
    8. Transforming a List
    9. Sorting Lists
    10. Sorting on Multiple Comparisons
    11. Summary
  8. 7. When Things Go Wrong
    1. Exceptions
      1. Catching Exceptions
      2. Backtraces
      3. Rethrowing Errors
      4. Throwing Your Own Exceptions
      5. Defining Your Own Exception Types
    2. Failures
    3. Warnings
    4. The Wisdom of Exceptions
    5. Summary
  9. 8. Files and Directories, Input and Output
    1. File Paths
      1. File Test Operators
      2. File Metadata
      3. Linking and Unlinking Files
      4. Renaming and Copying Files
    2. Manipulating Directories
      1. Directory Listings
      2. Creating Directories
      3. Removing Directories
    3. Formatted Output
      1. Common Formatting Tasks
    4. The Standard Filehandles
      1. Standard Output
      2. Standard Error
      3. Standard Input
    5. Reading Input
      1. Reading Lines
      2. Reading a File
    6. Writing Output
      1. Opening a File for Writing
    7. Binary Files
      1. Moving Around
      2. Writing Binary Files
    8. Summary
  10. 9. Associatives
    1. Pairs
      1. Adverbs
      2. Modifying a Pair
    2. Maps
      1. Checking Keys
      2. Creating from a Positional
      3. Checking Allowed Values
    3. Hashes
      1. Accumulating with a Hash
    4. Multilevel Hashes
    5. Summary
  11. 10. Using Modules
    1. Installing Modules
    2. Loading Modules
      1. Finding the Module
      2. Lexical Effect
      3. Loading a Module at Runtime
    3. Fetching Data from the Web
    4. Running Perl 5 in Perl 6
    5. Summary
  12. 11. Subroutines
    1. A Basic Subroutine
      1. Extra Arguments
      2. Explicit Returns
    2. Recursing
      1. Iterating Instead of Recursing
    3. Storing Subroutines in Libraries
      1. Exporting Subroutines
    4. Positional Parameters
      1. Slurpy Parameters
      2. Have It Both Ways
      3. Combining Slurpies
      4. Optional and Default Arguments
      5. Parameter Traits
      6. Parameter Constraints
    5. Same Name, Different Signature
      1. Literal Value Parameters
      2. Number of Arguments
      3. Parameter Types
    6. Named Parameters
      1. Required Named Parameters
      2. Named Parameters for Free
      3. Mixed Parameters
    7. Return Types
    8. Summary
  13. 12. Classes
    1. Your First Class
    2. Defining Methods
      1. Private Methods
      2. Defining Subroutines
    3. Objects
      1. Private Attributes
      2. Public Attributes
    4. multi Methods
    5. Inheriting Types
      1. Checking Inheritance
      2. Stub Methods
    6. Controlling Object Creation
      1. Building Objects
      2. Tweaking Objects
    7. Private Classes
    8. Summary
  14. 13. Roles
    1. Adding Behavior to Classes
      1. Applying Multiple Roles
    2. Methods in Roles
    3. De-Conflicting Roles
    4. Anonymous Roles
    5. Summary
  15. 14. Junctions and Sets
    1. Junctions
      1. any
      2. all
      3. one
      4. none
      5. Some Junctive Tricks
    2. Sets
      1. Set Operations
    3. Summary
  16. 15. Regular Expressions
    1. The Match Operator
      1. Match Operator Syntax
      2. Successful Matches
      3. Defining a Pattern
      4. Predefined Patterns
    2. Matching Nonliteral Characters
      1. Matching Any Character
      2. Matching Types of Characters
      3. User-Defined Character Classes
    3. Matching Adverbs
      1. Matching Either Case
      2. Ignoring Marks
      3. Global Matches
    4. Things That Use Patterns
      1. Substitutions
    5. Summary
  17. 16. Fancier Regular Expressions
    1. Quantifiers
      1. Zero or More
      2. Greediness
      3. Zero or One
      4. Minimal and Maximal
    2. Controlling Quantifiers
      1. Turning Off Backtracking
    3. Captures
      1. Named Captures
      2. A Capture Tree
      3. Backreferences
    4. Surrounders and Separators
    5. Assertions
      1. Anchors
      2. Conditions
      3. Code Assertions
    6. Alternations
      1. First Match
      2. Longest Token Matching
    7. Summary
  18. 17. Grammars
    1. A Simple Grammar
    2. Multiple Rules
    3. Debugging Grammars
      1. Grammar::Tracer
      2. Grammar::Debugger
    4. A Simple Action Class
      1. Creating an Abstract Syntax Tree
    5. Ratcheting
    6. Parsing JSON
    7. Parsing CSV
      1. Adjusting the Grammar
      2. Using Roles in Grammars
    8. Summary
  19. 18. Supplies, Channels, and Promises
    1. Supplies
      1. Multiple Taps
      2. Live Supplies
    2. Channels
    3. Promises
      1. Waiting for Promises
      2. Waiting for Multiple Promises
      3. Managing Your Own Promises
      4. Promise Junctions
    4. Reactive Programming
      1. Reacting in the Background
    5. Summary
  20. 19. Controlling Other Programs
    1. Quick and Easy
      1. Quoted Commands
      2. Safer Commands
      3. Writing to a Proc
    2. Procs
    3. Asynchronous Control
    4. Summary
  21. 20. Advanced Topics
    1. One-Liners
    2. Declarator Block Comments
    3. Feed Operators
    4. Destructuring Signatures
    5. Defining Your Own Operators
    6. Perl 5 Patterns
    7. Shaped Arrays
    8. Typed Containers
    9. NativeCall
    10. The with Topicalizer
  22. 21. Conclusion
  23. Glossary
  24. A. Exercise Answers
    1. Answers to Preface Exercises
    2. Answers to Chapter 1 Exercises
    3. Answers to Chapter 2 Exercises
    4. Answers to Chapter 3 Exercises
    5. Answers to Chapter 4 Exercises
    6. Answers to Chapter 5 Exercises
    7. Answers to Chapter 6 Exercises
    8. Answers to Chapter 7 Exercises
    9. Answers to Chapter 8 Exercises
    10. Answers to Chapter 9 Exercises
    11. Answers to Chapter 10 Exercises
    12. Answers to Chapter 11 Exercises
    13. Answers to Chapter 12 Exercises
    14. Answers to Chapter 13 Exercises
    15. Answers to Chapter 14 Exercises
    16. Answers to Chapter 15 Exercises
    17. Answers to Chapter 16 Exercises
    18. Answers to Chapter 17 Exercises
    19. Answers to Chapter 18 Exercises
    20. Answers to Chapter 19 Exercises
  25. Index

Product information

  • Title: Learning Perl 6
  • Author(s): brian d foy
  • Release date: September 2018
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491977682