NAME

Learning RPerl

BOOK TITLE

Learning RPerl

~ or ~

Let's Write Fast Perl!

.
...
.....
.......
being
.......
.....
...
.

The Official Introductory-Level Reference, User Manual, and Educational Documentation

~ for ~

Restricted Perl, The Optimizing Perl 5 Compiler


DEDICATION

For Anna.


EDITION

0th Edition, Pre-Release Copy

Automatically Generated From RPerl/Learning.pm v0.073
Using pod2rperlhtml.pl v0.023
On Tuesday, May 9d, 2016 at 9:44am CDT


TABLE OF CONTENTS: CHAPTERS AT-A-GLANCE


FOREWORD

[ INSERT FOREWORD CONTENT HERE ]


PREFACE

Section 0.1: Who I Am

My name is William N. Braswell, Jr.; I am also known by a number of other names including Will the Chill, The Voice In The Wilderness, Skipper Brassie ("braz-ee"), and just Will.

I have a degree in computer science and mathematics from Texas Tech University, I have worked as a Perl software developer for over 15 years, and I am the founder of the Auto-Parallel Technologies consulting company.

LinkedIn Profile

GitHub Profile

I am 1 of 3 co-founders of the Perl 11 movement.

Perl11.org

I am also the President of the Austin Perl Mongers.

Austin.pm

Most importantly, I am the creator of the RPerl optimizing compiler for Perl 5, about which you are currently reading!

RPerl.org

Section 0.2: Why I Wrote This Book

Using RPerl is different enough from normal Perl 5 to necessitate the creation of in-depth user documentation.

Manual pages and cookbooks and example source code alone are not enough, only a full textbook can provide the level of detail necessary to truly learn RPerl.

This is that textbook.

Section 0.3: History Of This Book

RPerl v1.0 was released on US Independence Day, July 4th, 2015; 6 days later, work began on the source code solution to exercise 1 of chapter 1 of this book:

First Learning RPerl Commit on GitHub

Significant GitHub commit dates include, but are not limited to the following:

    $ git log --reverse --all --date=short --pretty='%cd: %s' | grep 'Learning RPerl'
    2015-07-10: Learning RPerl, Chapter 1, Exercise 1, Hello World
    2015-07-11: Learning RPerl, Chapter 2, Exercise 1, Circumference Of Circle With Radius 12.5
    2015-07-12: Learning RPerl, Chapter 2, Exercise 1, Circumference Of Circle With Radius 12.5, Part 2
    2015-07-13: Learning RPerl, Chapter 2, Exercise 2, Circumference Of Circle With Any Radius
    2015-07-14: Learning RPerl, Chapter 2, Exercise 3, Circumference Of Circle With Any Positive Radius
    2015-07-15: Learning RPerl, Chapter 2, Exercise 4, Product Of Any Two Numbers
    2015-07-16: Learning RPerl, Chapter 2, Exercise 5, String Repeat
    2015-07-18: Learning RPerl, Chapter 3, Exercise 1, STDIN Strings Reverse
    2015-07-17: Learning RPerl, Chapters 1 & 2, Add Source Comments
    2015-07-19: Learning RPerl, Chapter 3, Exercise 2, STDIN Array Indices
    2015-07-20: Learning RPerl, Chapters 2 & 3, Add Source Comments
    2015-07-21: Learning RPerl, Chapter 3, Exercise 3, STDIN Strings Sort
    2015-07-22: Learning RPerl, Chapter 4, Exercise 1, Subroutine For Stringified Numbers Total
    2015-07-23: Learning RPerl, Chapter 4, Exercise 2, Subroutine For Total Of 1 To 1,000
    2015-07-25: Learning RPerl, Chapter 4, Exercise 3, Subroutines For Above-Average Array Elements
    2015-10-03: Learning RPerl, Chapter 4, Exercise 4, Subroutine To Greet User
    2015-10-04: Learning RPerl, Chapter 4, Exercise 5, Subroutine To Greet Multiple Users
    2015-10-05: Learning RPerl, Chapter 5, Exercise 1, Print Input File(s) Lines In Reverse, Part 1
    2015-10-06: Learning RPerl, Chapter 5, Exercise 1, Print Input File(s) Lines In Reverse, Part 2
    2015-10-07: Learning RPerl, Chapter 5, Exercise 2, Print Input Line(s) Right-Justified
    2015-10-08: Learning RPerl, Chapter 5, Exercise 3, Print Input Line(s) Variable-Width Right-Justified, Part 1
    2015-10-09: Learning RPerl, Chapter 5, Exercise 3, Print Input Line(s) Variable-Width Right-Justified, Part 2
    2015-10-10: Learning RPerl, Chapter 6, Exercise 1, Print Family Names
    2015-10-11: Learning RPerl, Chapter 6, Exercise 2, Unique Word Count
    2015-10-12: Learning RPerl, Ensure All Exercises Parse, Part 1
    2015-10-13: Learning RPerl, Ensure All Exercises Parse, Part 2
    2015-10-19: Learning RPerl, Ensure All Exercises Parse, Part 3
    2015-10-20: Learning RPerl, Ensure All Exercises Parse, Part 4
    2015-10-21: Learning RPerl, Ensure All Exercises Parse, Part 5
    2015-10-22: Learning RPerl, Ensure All Exercises Parse, Part 6
    2015-10-23: Learning RPerl, Ensure All Exercises Parse, Part 7
    2015-10-24: Learning RPerl, Ensure All Exercises Parse, Part 8
    2015-10-25: Learning RPerl, Ensure All Exercises Parse, Part 9
    2015-10-26: Learning RPerl, Ensure All Exercises Parse, Part 10
    2015-10-27: Learning RPerl, Ensure All Exercises Parse, Part 11
    2015-10-28: Learning RPerl, Ensure All Exercises Parse, Part 12
    2015-10-28: Learning RPerl, Ensure All Exercises Parse, Part 13
    2015-10-28: Learning RPerl, Ensure All Exercises Parse, Part 14
    2015-11-07: CPAN Release, v1.200002; Temporarily Fix Macintosh Build Failures, Learning RPerl Parse Failure, Etc.
    2015-11-10: Learning RPerl, Content, Part 1
    2015-11-11: Learning RPerl, Content, Part 2
    2015-11-14: Learning RPerl, Content, Part 3
    2015-11-15: Learning RPerl, Content, Part 4
    2015-11-16: Learning RPerl, Content, Part 5
    2015-11-16: Learning RPerl, Content, Part 6
    2015-11-17: Learning RPerl, Content, Part 7
    2015-11-18: Learning RPerl, Content, Part 8
    2015-11-18: Learning RPerl, Content, Part 9
    2015-11-19: Learning RPerl, Content, Part 10
    2015-11-20: Learning RPerl, Content, Part 11
    2015-11-21: Learning RPerl, Content, Part 12
    2015-11-22: Learning RPerl, Content, Part 13
    2015-11-24: Learning RPerl, Content, Part 14
    2015-12-31: Learning RPerl, Content, Part 15
    2015-12-31: Learning RPerl, Content, Part 16
    2016-01-01: Learning RPerl, Content, Part 17
    2016-01-02: Learning RPerl, FontAwesome & MetaCPAN Files, Initial Commit
    2016-01-02: News, RPerl v1.5 Release; Learning RPerl, FontAwesome & MetaCPAN Files, Move To Subdirectories
    2016-01-02: Learning RPerl, Update pod2rperlhtml.pl Script, Correct CSS & JS Paths
    2016-01-02: Learning RPerl, HTML Content, Initial Commit
    2016-01-03: Learning RPerl, Content, Part 18
    2016-01-05: Learning RPerl, Content, Part 19
    2016-01-06: Learning RPerl, Content, Part 20
    2016-01-07: Learning RPerl, Content, Part 21
    2016-01-08: Learning RPerl, Content, Part 22
    2016-01-09: Learning RPerl, Content, Part 23
    2016-01-09: Learning RPerl, Content, Part 24
    2016-01-10: Learning RPerl, Content, Part 25
    2016-01-11: Learning RPerl, Content, Part 26
    2016-01-12: Learning RPerl, Content, Part 27
    2016-01-14: Learning RPerl, Content, Part 28
    2016-01-15: Learning RPerl, Content, Part 29
    2016-01-16: Learning RPerl, Content, Part 30
    2016-01-16: Learning RPerl, Content, Part 31
    2016-01-16: Learning RPerl, Content, Part 32
    2016-03-03: Learning RPerl, Chapter 2 Content, Part 1
    2016-03-03: Learning RPerl, TPF Grant #2, Part 1

Section 0.4: TPF Grants

This book was made possible in part by 2 generous grants from The Perl Foundation, as part of the September 2015 and January / Febuary 2016 rounds of funding.

Special thanks to TPF Grants Committee Secretary, Makoto Nozaki; TPF Grant Manager, Mark Jensen; TPF Grants Committee's various supporting members; and everyone who gave positive feedback on the grant proposals.

A history of TPF grant #1 may be found at the following links:

A history of TPF grant #2 may be found at the following links:

Section 0.5: Acknowledgements & Thanks

Countless people have contributed to the development of RPerl; from source code to bug testing to financial donations to emotional support, it truly takes a village to build a compiler!

Below are the contents of the official RPerl thank-you file, listing the handles (online nicknames) and names of the most important RPerl contributors. If you don't already know who these people are, you will be pleasantly surprised by researching each of them.

Latest THANKS File

    Many Thanks To irc.perl.org:

    #perl5 Founder timtoady

    #perl6 Founder timtoady (again)

    #perl11 Founders ingy & rurban & willthechill (yours truly)

    #perl11 Members bulk88 & mst

    #inline Founders ingy (again) & nwatkiss

    #inline Members davido & mohawk & sisyphus


    Additional Thanks To:

    Eyapp Creator Casiano Rodriguez-Leon, PhD

    Austin Perl Mongers

    All RPerl Contributors & Users & Supporters

Section 0.6: Defense / Apology

I'm sure I will make errors while writing this book.

I may even upset some people, particularly those who have an emotional or financial investment in slow Perl software.

Despite my best efforts, I remain a fallible human being; thus, bad spelling and grammer and run-on sentences and parts that are hard to understand and parts that are not funny and formattiNg errors and bad spelling adn repetitions and other annoyances will doubtless plague this tome but we must not allow such trivialities as, improper punctuation to affect our willingness and ability to learn how to write super-fast RPerl software.

If you find a mistake in this book (other than in the immediately preceeding paragraph), please utilize the following link to create a new GitHub issue (bug report) using a title starting with the words "Learning RPerl":

New GitHub Issue

I will try my best to create an engaging and educational experience for you, the reader; however, in anticipation of the inevitable disappointment you may experience, I can only humbly offer...

I'M SORRY!

Section 0.7: POD

"The Pod format is not necessarily sufficient for writing a book."

http://perldoc.perl.org/perlpod.html

~ Saint Larry Wall & Sean M. Burke


"Challenge accepted."

https://github.com/wbraswell/rperl/blob/master/script/development/pod2rperlhtml.pl

~ Will Braswell


CHAPTER 1: INTRODUCTION

Section 1.1: Welcome To The Roadrunner Book!

You are about to learn the basic concepts of writing software using the RPerl optimizing compiler for the Perl computer programming language. With the skills gained by reading this book, you will be empowered to create new super-fast RPerl programs which can be intermixed with the enormous amount of existing Perl software available on the Internet.

This book is named and stylized for the animal mascot for RPerl, Roadie the Roadrunner. RPerl, like Roadie, "runs really fast".

Throughout this text, the following 12 typography conventions are utilized:

Section 1.2: Learning Perl

This book is purposefully patterned after the popular educational text Learning Perl, affectionately known as the Llama Book. Both the Roadrunner Book and the Llama book are meant as introductory texts on Perl topics. The Llama Book is focused on normal Perl, and the Roadrunner Book is focused on optimized Perl.

This book copies the same chapter topics as Learning Perl, but all content is re-written for RPerl. Learning RPerl also copies the same exercise concepts as Learning Perl, but all solutions are re-written in RPerl. Both books are canonical and may be used together in the classroom; the source code solutions are meant to be compared side-by-side as textbook examples of normal Perl versus optimized Perl.

Please support the Perl community by purchasing a copy of Learning Perl from our friends at O'Reilly:

http://shop.oreilly.com/product/0636920018452.do

Section 1.3: Is This Book Right For You?

If you answered "yes" to any of these questions, then the Roadrunner Book is definitely for you!

If you answered "no" to all of these questions, then this book may still be for you, give it a try!

If you hate Perl, or only love slow software, or wish all computers would explode, then we suggest some soul-searching and a few Saint Larry videos. You'll thank us in the morning.

Section 1.4: Why Aren't There More Footnotes?

This is a purposefully simple book, in the same way RPerl is a purposefully simple subset of the full Perl 5 programming language.

Section 1.5: What About The Exercises & Their Answers?

There are one or more programming exercises at the end of every chapter, and full answers to each problem are given near the end of the book in Appendix A.

For maximum educational effect, we suggest you attempt to write each piece of code on your own before looking at our solutions.

If you are using this as an official textbook for certification or academic credit, such as at LAMPuniversity.org or a traditional school, you are obviously expected to write all your own code without refering to our or anyone else's solutions whatsoever. We suggest you enclose Appendix A with a paperclip or discard it altogether to avoid the potential for accidental academic dishonesty.

Section 1.6: What Do Those Numbers At The Start Of The Exercise Mean?

The original authors of Learning Perl meant the numbers at each exercise to indicate the approximate number of minutes required for an average person to reach a full working solution. If it takes you less time, good for you! If it takes you more time, don't worry, it's no big deal; learning technical skills requires time and dedication. All experts were once novices.

Section 1.7: What If I'm An RPerl Course Instructor?

Thank you for helping spread the love of Perl and the speed of RPerl!

As previously mentioned, this book may either be used solo or combined with Learning Perl. For students who are not already familiar with Perl, you may wish to use this text alone in order to simplify and ease the learning experience. For students who are already familiar with Perl or other dynamic programming languages like the snake or the red gemstone, you may wish to use both textbooks for a more in-depth compare-and-contrast approach.

Section 1.8: What Does RPerl Stand For?

RPerl stands for "Restricted Perl", in that we restrict our use of Perl to those parts which can be made to run fast. RPerl also stands for "Revolutionary Perl", in that we hope RPerl's speed will revolutionize the software development industry, or at least the Perl community. RPerl might even stand for "Roadrunner Perl", in that it runs really fast.

Section 1.9: Why Did Will Create RPerl?

Will loves Perl and the Perl community.

Will is a scientist and needs his code to run really fast.

Will doesn't like the hassle of writing code in C or C++ or XS or Inline::C or Inline::CPP.

Will waited a decade or two before realizing he had to do it himself.

Section 1.10: Why Didn't Will Just Use Normal Perl Or Some Other Language?

Dynamic languages like Perl are fast at running some kinds of computational actions, such as regular expressions (text data pattern matching) and reading from a database.

Unfortunately, dynamic languages are slow at running general-purpose computations, such as arithmetic and moving data around in memory. Sometimes very slow.

Dynamic languages like Perl are also flexible, powerful, and relatively easy to learn. Sometimes too flexible.

RPerl's goal is to keep all of Perl's power and ease-of-use, while removing the redundant parts of Perl's flexibility in order to gain a major runtime speed boost.

The most complex and flexible parts of Perl are called "high magic", so RPerl is focused on supporting the "low magic" parts of Perl which can be made to run fast.

Section 1.11: Is RPerl Easy Or Hard?

RPerl is specifically designed to remove the confusing and complicated parts of Perl.

RPerl also introduces a number of additional rules and templates which are not present in normal Perl, notably including the use of real data types.

The net effect of removing Perl complexity and adding RPerl rules falls in favor of RPerl, due primarily to the exceedingly complex nature of Perl.

In other words, RPerl is easier to learn and use than dynamic languages like normal Perl, and most any other language in general.

Section 1.12: How Did RPerl Get To Be So Popular?

The RPerl team has been regularly promoting RPerl in a number of physical and digital venues, including but not limited to:

Section 1.13: What Is Happening With RPerl Now?

As of Q2 2016, RPerl v1.7 (codename Tycho) has been publicly released and is in use by a number of early adopters around the world.

RPerl development is proceeding with financial support from both Kickstarter crowdfunding and official grant monies from The Perl Foundation.

The RPerl community is beginning to grow, and there are a number of exciting RPerl projects currently in the works. More info coming soon!

Section 1.14: What Is RPerl Really Good For?

RPerl is a general-purpose programming language, which means you can use RPerl to efficiently and effectively implement virtually any kind of software you can imagine.

RPerl is especially well-suited for building software which benefits from speed, such as scientific simulations and graphical video games.

RPerl is also good for building software which utilizes Perl's strong-suit of string manipulation; RPerl currently supports basic string operators, with full regular expression support to be added in an upcoming version.

Section 1.15: What Is RPerl Not Good For?

RPerl has purposefully disabled the most complex features of Perl, such as run-time code evaluation, secret operators, and punctuation variables. If you have purposefully designed your Perl software to depend on these high-magic features, or you are unconditionally committed to continue using high-magic language features, then maybe RPerl isn't for you.

Section 1.16: How Can I Get RPerl?

Installing RPerl ranges from easy to difficult, depending on how well your operating system supports Perl and C++.

On modern operating systems with good Perl support, such as Debian or Ubuntu GNU/Linux, you should be able to install RPerl system-wide by running the following command at your terminal command prompt:

    $ sudo cpan RPerl

If RPerl is properly installed, you should see a short text message displayed when you type the following command:

    $ rperl -v

On operating systems with less Perl support, you may have to perform a number of steps to successfully install RPerl, with dry technical detail available in the INSTALL notes document:

https://github.com/wbraswell/rperl/blob/master/INSTALL

Unless you are an experienced programmer or system administrator, it is strongly recommended you use the Xubuntu operating system. You can download the Xubuntu ISO file at the link below, then use it to create a bootable DVD disc or USB flash drive, install Xubuntu onto any computer, and issue the $ sudo cpan RPerl command as described above.

http://xubuntu.org/getxubuntu

If you are interested in viewing the source code of RPerl itself, you may find the latest major release of RPerl (stable) on CPAN:

https://metacpan.org/author/WBRASWELL

You may find the latest development release of RPerl (possibly unstable) on Github:

https://github.com/wbraswell/rperl

Section 1.17: What Is CPAN?

CPAN is the "Comprehensive Perl Archive Network", the world's most successful and mature centralized software network.

CPAN servers are where most public Perl software is stored, including RPerl.

https://en.wikipedia.org/wiki/CPAN

http://www.cpan.org

Several other programming language communities have copied the success and implementation of CPAN, including JSAN for Javascript, CRAN for R, and CCAN for C.

Section 1.18: How Can I Get Support For RPerl?

Official RPerl technical support is provided through Auto-Parallel Technologies, Inc.

To request more information, please send an e-mail to the following address (remove "NOSPAM DOT" before sending):

william DOT braswell AT NOSPAM DOT autoparallel DOT com

Section 1.19: Are There Any Other Kinds Of Support?

Free technical support for non-commercial users is provided by the RPerl community through IRC.

IRC #perl11 http://irc.perl.org

Section 1.20: What If I Find A Bug In RPerl?

The primary bug-tracking platform for RPerl is Github Issues, where you may file a new bug report ("new issue") if it is not already listed:

https://github.com/wbraswell/rperl/issues

Although Github Issues is strongly preferred, the RPerl development team also supports the legacy CPAN ticket system:

https://rt.cpan.org/Public/Dist/Display.html?Name=RPerl

Section 1.21: How Do I Make An RPerl Program?

Computer programs written using the RPerl language are plain text files, which means you can use any text editor to create and modify your RPerl source code. Examples of common text editors include Notepad, Pico, and Vi.

http://www.vim.org

To avoid possible file format problems, do not edit your RPerl programs using a word processor such as Wordpad, Word, OpenOffice, or LibreOffice.

Experienced RPerl developers may choose to utilize an "integrated development environment" (IDE), which is a special text editor made for writing software. Examples of common Perl IDE applications include Eclipse EPIC, Padre, and Komodo (non-free).

http://www.epic-ide.org

http://padre.perlide.org

http://komodoide.com/perl

Section 1.22: A Simple RPerl Program

    #!/usr/bin/perl
    
    # Foo Bar Arithmetic Example
    
    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;
    
    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(RequireInterpolationOfMetachars)  # USER DEFAULT 2: allow single-quoted control characters & sigils
    
    # [[[ OPERATIONS ]]]
    my integer $foo = 21 + 12;
    my integer $bar = 23 * 42 * 2;
    my number  $baz = to_number($bar) / $foo;
    print 'have $foo = ' . to_string($foo) . "\n";
    print 'have $bar = ' . to_string($bar) . "\n";
    print 'have $baz = ' . to_string($baz) . "\n";

Section 1.23: What Is Inside That RPerl Program?

This program is separated by blank lines into 4 sections: shebang, header, critics, and operations.

Other than the shebang and critics, all lines beginning with # are comments and can be safely ignored or discarded without affecting the program.

The "shebang" section is required, always contains exactly 1 line, and is short for "hash bang"; referring to the two leading characters #! of this line. The "octothorpe" character # (tic-tac-toe symbol) is called a "pound sign" when used on a telephone, and is called a "hash" (or more recently and less accurately "hash tag") when used on a computer. The exclamation point character ! is called a "bang" when used on a computer. When appearing together as the first two characters in a plain text file, the hash and bang characters tell the operating system to run the immediately-following command (in this case the Perl interpreter located at /usr/bin/perl) and pass the remaining contents of the text file as input to the command. In other words, if the first line of a plain text file is #!/usr/bin/perl, then that file is a Perl program.

The "header" section is required and always contains 4 lines for an RPerl "program" file ending in .pl, or 5 lines for an RPerl "module" ending in .pm (covered later in Chapter 11). use is recognized by Perl as a special "keyword" (AKA "built-in operator") which has 2 primary purposes: to load additional RPerl modules, and to enable RPerl "pragma" system configuration modes. The use RPerl; line is dual-purpose, it both loads the RPerl.pm module and enables the special RPerl low-magic pragma. The use strict; and use warnings; lines enable basic Perl pragmas which require decent programming practices by the human programmers. The our $VERSION = 0.001_000; line sets the version number of this RPerl program.

The "critics" section is included as necessary and may contain 1 or more lines beginning with ## no critic, which disable the errors caused by the over-restrictive nature of some Perl::Critic policies. There are currently 6 critics commands enabled for normal RPerl users, the first 2 of which are given in this example. The USER DEFAULT 1 critics command allows the use of numeric values such as 21 and 12, as well as the common print command. The USER DEFAULT 2 critics command allows the printing of 'have $foo = ', where a single-quoted ' string literal value contains the the $ dollar sigil (covered later in Chapter 2).

The "operations" section is required and contains 1 or more lines of general-purpose RPerl source code. This is the main body of your program. The 6 lines of source code in our example are used to perform some simple arithmetic and display the results. The my integer $foo = 21 + 12; line declares a new variable named $foo which will only contain non-floating-point numeric data, and which is initialized to contain the arithmetic result of numeric literal values 21 plus 12. The my integer $bar = 23 * 42 * 2; line does much the same thing, creating a new numeric variable named $bar and initialized with 23 times 42 times 2. The my number $baz = to_number($bar) / $foo; line creates a new floating-point numeric variable $baz, and initializes it to the quotient of the $bar and $foo variables. The to_number() RPerl type conversion subroutine converts a non-floating-point integer value to a floating-point number value.

The print 'have $foo = ' . to_string($foo) . "\n"; and following 2 lines will display on screen (not send to paper printer) the labeled values of $foo, $bar, and $baz respectively. The . dot operator is string concatenation, used in this example to create one string out of 3 parts so there is only 1 argument parameter passed to the print command. The to_string() RPerl type conversion subroutine converts the numeric values to underscore-formatted string values, suitable for use via the print operator. The "n" in the "\n" double-quoted string literal values stands for "newline", which inserts a carriage return to place the next piece of printed data down on the following line.

Section 1.24: How Do I Compile RPerl?

Normal Perl source code is executed using a software mechanism known as "interpretation", which is to say that Perl is an "interpreted" language and the /usr/bin/perl command is called the "Perl interpreter". The primary alternative to interpretation is "compilation", so RPerl is a "compiled" subset of the Perl language and the /usr/bin/rperl command is called the "RPerl compiler".

Like the Perl interpreter, the RPerl compiler accepts 2 different input file types: Perl programs which end in .pl and Perl modules which end in .pm. Perl program files actually run and execute actions, optionally receiving some functionality from 1 or more Perl module files if specified. Perl modules do not run or execute actions themselves, they only provide functionality which must in turn be called from a Perl program, or from another Perl module which eventually gets called by a Perl program.

A list of all valid RPerl compiler options may be seen by issuing the following command:

    $ rperl -?

You may find the same information by viewing the following links:

rperl

https://metacpan.org/pod/distribution/RPerl/script/rperl

To compile-then-execute the preceeding RPerl example program, you may copy and paste the entire program (from shebang to second print) into a temporary file such as /tmp/foobar.pl, then execute the following command:

    $ rperl /tmp/foobar.pl

The output of this example program should be:

    have $foo = 33
    have $bar = 1_932
    have $baz = 58.545_454_545_454_5

If the compilation is successful, a new compiled executable file will be created in /tmp/foobar. You may then directly execute the compiled program as many times as you like, without needing to recompile it using the `rperl` command, and you should receive the exact same output as the non-compiled code:

    $ /tmp/foobar
    have $foo = 33
    have $bar = 1_932
    have $baz = 58.545_454_545_454_5

Please see "CHAPTER 11: CLASSES, PACKAGES, MODULES, LIBRARIES" for more information about compiling Perl modules.

Section 1.25: A Whirlwind Tour of RPerl

Section 1.25.1: Creator Of RPerl, Will Braswell

Will Braswell does more than just create Perl compiler software, he is also very active in several other areas of life, including but not limited to:

These areas of interest are reflected in the tone and intention of RPerl.

Section 1.25.2: History Of RPerl

The RPerl project officially began as a New Year's Resolution on January 1st, 2013. Following the grand tradition of Perl creator "Saint" Larry Wall, RPerl version releases are often timed to coincide with major holidays.

After 1 year of work, RPerl v1.0beta1 was released on New Year's Day 2014, eventually followed by RPerl v1.0beta2 on Christmas 2014.

The much-anticipated RPerl v1.0 full release was made on US Independence Day 2015, and RPerl v1.2 came on Halloween 2015.

RPerl v1.3 was released on Thanksgiving 2015, followed by RPerl v1.4 on Christmas 2015, and so forth.

RPerl v1.0 was funded through a Kickstarter campaign, then RPerl v1.2 and v1.3 were funded through a second Kickstarter campaign. Work on the first 6 chapters of this book was funded, in part, by a grant from The Perl Foundation.

Section 1.25.3: Performance Of RPerl

The question of "How fast is RPerl?" does not have one simple answer; instead there are several factors and configuration modes to be taken into consideration. A relatively detailed description of the performance and modes may be found at the following link:

http://rperl.org/performance_benchmarks.html

The most condensed answer is that "RPerl is really fast." Utilizing RPerl's fastest execution modes, we see performance very close to the highly-optimized C++ programming language, which means RPerl is now among the short list of "world's fastest languages" along with C, C++, and Fortran.

Section 1.25.4: The Low-Magic Perl Commandments

The high-magic features of Perl are primarily responsible for how slow Perl runs for general-purpose computations. The "R" in RPerl stands for "Restricted", in that we restrict ourselves to only use the low-magic features of Perl which can run really fast.

The definitive list of do's and do-nots for high-magic vs low-magic Perl programming is called The Low Magic Perl Commandments (LMPC). There are 64 total commandments split into 5 groups of Ideals, Magic, Data, Operations, and Object-Orientation. The "Thou Shalt" commandments appear in the left column, and the "Thou Shalt Nots" appear on the right.

http://rperl.org/the_low_magic_perl_commandments.html

The LMPC draw inspiration from, and (wherever possible) work together with Damian Conway's Perl Best Practices and Jeffrey Thalhammer's Perl::Critic software.

http://shop.oreilly.com/product/9780596001735.do

http://search.cpan.org/~thaljef/Perl-Critic/lib/Perl/Critic/PolicySummary.pod

Section 1.25.5: Perlism & The Book Of RPerl

Perlism is the computer religion dedicated to the use, promotion, and development of the Perl family of programming languages. (Not to be confused with a spiritual religion such as Christianity, a computer religion such as Perlism is an independent and complementary belief structure.)

A Perlite is an adherent to the Perlism religion. Perlism has a revered founder, Saint Larry (himself a devout Christian); a prophet, The Voice In The Wilderness (Will); a monastary and shrine, Perl Monks; commandments, The LMPC; proverbs from Saint Larry including TIMTOWTDI, LMFB, and HTAAOF; and canonical scriptures, including Saint Larry's Apocalypses and The Voice's The Book Of RPerl.

The Book is a description of events surrounding the creation of RPerl and the future of the Internet. It is intended to both educate and entertain.

http://rperl.org/the_book_of_rperl.html

Section 1.25.6: Fun With Proverbs & Catch Phrases & Acronyms

St. Larry has given us short and powerful proverbs, some of which are meant to have a purposefully tongue-in-cheek or sarcastic interpretation.

Will has provided a corollary to each of St. Larry's official proverbs.

St. Larry's Original Proverb

Will's Corollary Proverb

3 Great Virtues Of A Programmer:

LIH (Laziness, Impatience, Hubris)

3 Greater Virtues Of A Programmer:

DPH (Diligence, Patience, Humility)

TIMTOWTDI (There Is More Than One Way To Do It)

TDNNTBMTOWTDI (There Does Not Need To Be More Than One Way To Do It)

TIOFWTDI (There Is One Fastest Way To Do It)

LMFB (Let Many Flowers Bloom)

PTBF (Pick The Best Flowers)

HTAAOF (Have The Appropriate Amount Of Fun)

DTAAOW (Do The Appropriate Amount Of Work)

In addition to St. Larry's official proverbs, there are a number of other commonly-used catch phrases and ideas in the Perl community.

Original Catch Phrase

Will's Corollary Catch Phrase

Perl 5 Is The Camel

Perl 5 Is The Raptor

Perl 6 Is The Butterfly

RPerl Is The Roadrunner

Perl Is The Onion

RPerl Is The Scallion

Perl Is The Swiss Army Chainsaw

RPerl Is The Sword

Perl Is Line-Noise

Perl Is A Write-Only Language

RPerl Is Best Practices

Section 1.26: Exercises

1. Hello World [ 15 mins ]

On a computer with RPerl already installed, create a directory named LearningRPerl containing a sub-directory named Chapter1. Using the Foo Bar example program as a template, manually type a new RPerl program into a file named exercise_1-hello_world.pl inside the LearningRPerl/Chapter1 sub-directory. The sole purpose of your first program is to use the print operator and simply display the following one line of text output, followed by one newline character:

    Hello, World!

Run your new program by issuing the following command at your terminal command prompt:

    $ rperl -t LearningRPerl/Chapter1/exercise_1-hello_world.pl

HINT: You only need the USER DEFAULT 1 critic line, so your resulting program should be 7 lines long, not counting comments or blank lines.

2. RPerl Commands [ 15 mins ]

First, run the following RPerl command, and observe the output for use in 2a and 2b below:

    $ rperl -?

2a. What are some RPerl command-line options with which you are already familiar?

2b. With which options are you unfamiliar?

Next, run the following 3 RPerl commands, for 2c and 2d below:

    $ rperl -t -V LearningRPerl/Chapter1/exercise_1-hello_world.pl
    $ rperl -t -D LearningRPerl/Chapter1/exercise_1-hello_world.pl
    $ rperl -t -V -D LearningRPerl/Chapter1/exercise_1-hello_world.pl

2c. How do the outputs of these 3 commands differ from the output of Exercise 1?

2d. How do the outputs differ from one another?

3. Foo Bar Arithmetic [ 15 mins ]

Manually type the entire Foo Bar Arithmetic example program into a file named exercise_3-foo_bar_arithmetic.pl inside the LearningPerl/Chapter1 sub-directory. (Even if you have already used copy-and-paste on the Foo Bar Arithmetic example program, you should still use this as an opportunity to build some RPerl muscle memory and type it in by hand.)

Modify your program by adding a new floating-point numeric variable named $zab, set its value to $foo divided by $bar (don't forget to_number()), change the starting value of $bar, and use print to generate the following output:

    have $foo = 33
    have $bar = 966
    have $baz = 29.272_727_272_727_3
    have $zab = 0.034_161_490_683_229_8

Run your program thusly:

    $ rperl -t LearningRPerl/Chapter1/exercise_3-foo_bar_arithmetic.pl


CHAPTER 2: SCALAR DATA

Most programming languages include the basic principles of using named "variables" to store data values such as numbers, text strings, and lists of multiple numbers or strings. Multiple variables may be created, each with different names such as $foo or $bar or $quux, and each potentially containing a different value.

A single piece of data, such as one number or one string, is called a "scalar". Multiple pieces of data combined into a single aggregate structure may be either an "array" or a "hash", described in chapters 3 and 6, respectively. (Although sharing the same terminology, the hash data structure is not related to the hash # tic-tac-toe character.) In normal Perl, only scalar variable names begin with the $ dollar sign "sigil", while aggregate data structures are stored in variables starting with different sigils like @ or %. In RPerl, all variable names begin the $ sigil, both scalar types and aggregate structures alike.

RPerl provides 7 scalar data types:

Of the 7 RPerl scalar data types, 3 are directly (natively) supported by the Perl 5 core: integer, number, and string. This means the Perl 5 core is capable of directly identifying and storing those 3 core types. The remaining 4 non-core types are indirectly supported by the Perl 5 interpreter: boolean and unsigned_integer can be stored within either an integer or number; character can be stored within a string; and gmp_integer is supported by the use bigint; wrapper around the Math::BigInt::GMP module.

When RPerl application source code is compiled from RPerl into C++, all 7 data types are natively supported by C++ for high-speed execution.

A single group of actual numeric digit(s) or quoted string character(s) is called a "literal", such as:

    -21         # integer or gmp_integer or number

    'howdy'     # string

    -23.421_12  # number

    1_234_567   # unsigned_integer or integer or gmp_integer or number

    1_234_567_890_123_456_789_012_345_678_901_234_567_890_123_456_789_012_345  # gmp_integer

    'One million, two-hundred-thirty-four thousand, five-hundred-sixty-seven'  # string

    '1'         # character or string

    'a'         # character or string

    "\n"        # newline character or string

    q{}         # empty character or string

    0           # boolean or unsigned_integer or integer or gmp_integer or number

Section 2.1: Numbers (Numeric Data & Operators)

RPerl provides 5 numeric data types:

Perl 5 provides several built-in operators designed for use with numeric data, which can be organized into 6 general categories:

Each operator in Perl 5 (and thus RPerl) is assigned 4 important characteristics: "arity" (a number), "fixity" (a placement location), "precedence" (a number) and "associativity" (a chirality or "handedness"). Operators of unary arity accept exactly 1 input operand, binary operators accept exactly 2 operands, etc. Prefix operators appear before their respective operands, postfix appear after, infix appear between, and closed operators appear both before and after their operands. Operators with a lower numeric precedence are executed before operators with a higher precedence; in the absence of parentheses, multiplication executes before addition because multiplication has a lower precedence number. Operators with equal precedence number are grouped by (and executed in order of) associativity; in the absence of parentheses, multiple subtraction operators will execute from left to right because subtraction is left-associative, whereas multiple exponent operators will execute from right to left because exponentiation is right-associative. For more information, see the Appendix:

B.3: Syntax Arity, Fixity, Precedence, Associativity

Beyond the built-in math operators in Perl 5, more advanced operators and functions are available via the MathPerl software suite, which is (perhaps unsurprisingly) optimized using the RPerl compiler.

MathPerl on CPAN

Section 2.1.1: Bool Literals

The most memory-efficient numeric literal is boolean, which represents a single "bit" (binary digit) of information. A boolean literal may only give the values of exactly 0 or 1.

    0     # boolean
    1     # boolean
    -1    # not a boolean
    1.5   # not a boolean
    -1.5  # not a boolean

Section 2.1.2: Unsigned Integer Literals

The second most efficient numeric literal is unsigned_integer, which represents a single whole (non-decimal) number greater than or equal to 0. An unsigned_integer literal may describe any positive whole number, within the data size limits of the data types supported by your operating system software and computer hardware. An unsigned_integer may not describe a negative number or a non-whole number.

    23      # unsigned_integer
    0       # unsigned_integer
    42_230  # unsigned_integer
    -23     # not an unsigned_integer
    42.1    # not an unsigned_integer
    999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999  # bad unsigned_integer, outside data type limits

Section 2.1.3: Integer Literals

The third most efficient numeric literal is integer, which represents a single whole (non-decimal) number. An integer literal may describe any positive or negative whole number, within your operating system and hardware data type limits.

    -23     # integer
    0       # integer
    42_230  # integer
    42.1    # not an integer
    -999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999  # bad integer, outside data type limits

Section 2.1.4: GMP Integer Literals

The GNU Multi-Precision (GMP) software library is utilized to provide the gmp_integer numeric literal, representing a single whole (non-decimal) number which may safely exceed the data type limits of your operating system and hardware. A gmp_integer literal may describe any positive or negative whole number, within the limits of the memory (real or virtual) available to your RPerl code.

    -23     # gmp_integer
    0       # gmp_integer
    42_230  # gmp_integer
    42.1    # not a gmp_integer
    -999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999  # gmp_integer

Section 2.1.5: Number Literals

The number numeric literal represents a single floating-point (decimal) number, and may express any real number within your computer's data type limits.

    -23.42     # number
    0.000_001  # number
    42.23      # number
    42         # number
    -4_123.456_789_123_456_789_123_456_789_123_456_789_123_456_789_123_456_789_123_456  # bad number, outside data type limits

Section 2.1.6: Underscore Digit Separators

For unsigned_integer, integer, gmp_integer, and number literals, an "underscore" _ character must be inserted after every third digit away from the decimal point, where the underscore is used in a similar manner as a comma when writing long numbers by hand.

    1_234_567  # integer, same as "1,234,567" in American notation
    -32_123    # integer, same as "-32,123" in American notation
    -32123     # bad integer, missing underscore

    1.234_567           # number, same as "1.234567" in American notation
    -32_123.456_789_01  # number, same as "-32,123.45678901" in American notation
    -32_123.456_78901   # bad number, missing underscore

Section 2.1.7: Optional Positive Sign

For unsigned_integer, integer, gmp_integer, and number literals, an optional + plus sign may be prepended to explicitly indicate a numeric literal is positive (greater than zero).

    1   # positive one
    +1  # also positive one

BEST PRACTICES

  • When only positive numeric literals are used in one area of code, omit positive signs.
  • When both positive and negative literals are used in one code area, use signs for all applicable literals.
    +23    # NOT BEST PRACTICE: not aligned with other unsigned literal below
    +55.6  # NOT BEST PRACTICE: not aligned with other unsigned literal below
    42

    23     #     BEST PRACTICE:     aligned with other unsigned literal below, best for all-positive literals
    55.6   #     BEST PRACTICE:     aligned with other unsigned literal below, best for all-positive literals
    42

    23     # NOT BEST PRACTICE:      not aligned with other signed literals below
    55.6   # NOT BEST PRACTICE:      not aligned with other signed literals below
    -21
    -66.5

     23    # NOT BEST PRACTICE: manually aligned with other signed literals below, but will not automatically align via Perl::Tidy
     55.6  # NOT BEST PRACTICE: manually aligned with other signed literals below, but will not automatically align via Perl::Tidy
    -21
    -66.5

    +23    #     BEST PRACTICE:          aligned with other signed literals below, best for mixed-sign literals
    +55.6  #     BEST PRACTICE:          aligned with other signed literals below, best for mixed-sign literals
    -21
    -66.5

Section 2.1.8: Scientific Notation

For unsigned_integer, integer, and number literals, very large or very small numbers may be approximated using "scientific notation", where each number is normalized to have exactly one digit to the left of the decimal point, then a lower-case e character and an appropriate integer power-of-ten is appended to the resulting normalized floating-point number. The e character stands for "exponent", as in "exponent of ten", and the Perl style of scientific notation is sometimes more accurately referred to as "scientific e notation".

As with normal integers, negative exponents must be prefixed with a - minus sign and positive exponents may be optionally prefixed with a + plus sign.

    1_234_567_000     # good integer
    1.234_567_000e09  # good number, same as "1_234_567_000" in scientific notation

    0.001_234_567_000  # good number
    1.234_567_000e-03  # good number, same as "0.001_234_567_000" in scientific notation

    -0.000_000_000_000_000_000_000_001_234_567  # bad number, outside data type limits
    -1.234_567e-24  # good number, same as "-0.000_000_000_000_000_000_000_001_234_567" in scientific notation

BEST PRACTICES

  • Use 2 digits to represent all exponents.
  • When only positive exponents are used, omit exponent signs.
  • When both positive and negative exponents are used, use signs for all exponents.
    1_234_567_000      # NOT BEST PRACTICE: no exponent
    1.234_567_000e9    # NOT BEST PRACTICE: not aligned with two-digit exponents below
    1.234_567_000e+09  # NOT BEST PRACTICE: not aligned with two-digit exponents below
    1.234_567_000e09   #     BEST PRACTICE:     aligned with two-digit exponents below, best for all-positive exponents
    1.234_567_000e19
    2.111_000_333e04

    1.234_567_000e09   # NOT BEST PRACTICE: not aligned with signed exponents below
    1.234_567_000e+09  #     BEST PRACTICE:     aligned with signed exponents below, best for mixed-sign exponents
    1.234_567_000e-09
    2.111_000_333e-04

    # accuracy of following numbers may be reduced on computers with lower precision data types
    +1.537_969_711_485_091_65e+21  # BEST PRACTICE: best for mixed-sign exponents
    -2.591_931_460_998_796_41e+01  # BEST PRACTICE: best for mixed-sign exponents
    +1.792_587_729_503_711_81e-01  # BEST PRACTICE: best for mixed-sign exponents
    +2.680_677_724_903_893_22e-03  # BEST PRACTICE: best for mixed-sign exponents
    +1.628_241_700_382_422_95e-03  # BEST PRACTICE: best for mixed-sign exponents
    -9.515_922_545_197_158_70e-15  # BEST PRACTICE: best for mixed-sign exponents

Section 2.1.9: Truth Values

In the most simple case, a "truth value" may be represented by a boolean literal where the numeric value of 0 represents the truth value of "false", and numeric 1 represents "true". In general, a truth value is any data which may be recognized by Perl (and thus RPerl) as being either true or false; there is no third option.

Perl recognizes relatively few values as false, of which only 4 are accepted by RPerl:

      0   # false, number zero
     '0'  # false, text   zero
    q{0}  # false, text   zero
    q{}   # false, text   empty

All other values which RPerl accepts are recognized to hold a truth value of true.

All numeric operators in the comparison and logic sub-categories, as well as all string operators in the comparison sub-category, will generate truth values as output.

Perl attaches magic to the truth value of false, allowing it be utilized as either a normal truth value, or a numeric value of 0, or an empty string value of q{}. This magic behavior is not supported by C++, and thus not supported by RPerl.

In C and C++, only numeric 0 is universally recognized as false, while the text 0 and empty text are recognized as true, which is different than Perl. To achieve compatibility, RPerl automatically inserts additional C++ logic in all compiled output code to check for the 2 remaining RPerl false values of text character zero '0' or q{0}, and empty text q{}. This ensures the compiled C++ output code will behave identically to the original RPerl input source code, with regard to truth values.

WARNING FOR ALL COMPARISON & LOGIC OPERATORS:

Due to Perl's magic attached to truth values of false, as well as the difference between Perl and C++ recognized truth values, you may experience unexpected or undefined behavior if a truth value is utilized anywhere except true-or-false conditions in loops and conditional statements.

Only utilize the truth values returned by comparison and logic operators within the condition enclosed by parentheses in if (), elsif (), for (), or while ().

    if    (1 > 2)     { print 'I think not'   . "\n"; }  # good use of greater-than operator
    elsif ($x and $y) { print 'Maybe'         . "\n"; }  # good use of          and operator

    for   (my integer $i = 0; $i < 23; $i++) { print 'finite loop'   . "\n"; }  # good use of less-than operator
    while (                    1 != 2      ) { print 'infinite loop' . "\n"; }  # good use of not-equal operator

    my integer $foo = 3 + (1 >= 2);   # UNEXPECTED BEHAVIOR: bad use of greater-than-or-equal operator
    my integer $bar = 3 * (1 <= 2);   # UNEXPECTED BEHAVIOR: bad use of    less-than-or-equal operator
    my integer $bat = sin (1 == 2);   # UNEXPECTED BEHAVIOR: bad use of                 equal operator

Section 2.1.10: Floating-Point Error

A "floating-point number" is any number which includes a decimal point . as part of the numeric representation, as opposed to an integer which does not include a decimal point. In RPerl, all floating-point values are stored in variables of the data type number.

       0  # integer
       1  # integer
    -123  # integer
    
       0.1    # floating-point
       1.654  # floating-point
    -123.4    # floating-point
    
    my integer $some_int   = 23;     # integer variable
    my number  $some_float = 23.42;  # floating-point variable

All computer languages which perform calculations on floating-point numbers are susceptible to "floating-point error", which is any inaccuracy due to incorrect rounding or lack of available precision.

For example, suppose you have a floating-point number 0.105, which seems normal enough. Let us further suppose you want to divide 0.105 by some other number, say 1_000, and by the simple rules of arithmetic you would expect to arrive at an answer of 0.000_105. Unfortunately, due to the way floating-point numbers are stored in computer memory, the actual result is closer to 0.000_104_999, so 0.000_105 happens to be one of many possible floating-point errors.

           (0.105 / 1_000) == 0.000_105    # UNEXPECTED BEHAVIOR: false
    print ((0.105 / 1_000) -  0.000_105);  # UNEXPECTED BEHAVIOR: -1.355_252_715_606_88e-20

It will usually not be possible to easily predict when and where floating-point error will occur. In general, you may experience the effects of floating-point error whenever your code relies upon one or more of the following:

To compensate for unpredictable floating-point error, you should use the "floating-point epsilon" value stored in the constant RPerl::EPSILON(), which is a very small number used to help detect inaccuracies. Whenever you want of directly compare two floating-point values, instead use the subtraction - and absolute value abs operators to take the positive difference, then use the less-than < operator to compare the difference to the floating-point epsilon value. If the difference is less than the floating-point epsilon, then the two input floating-point values can be considered to be numerically equal.

                                         RPerl::EPSILON()  # A VERY SMALL NUMBER: 0.000_000_000_000_000_2
         (0.105 / 1_000) == 0.000_105                      # UNEXPECTED BEHAVIOR: false
    abs ((0.105 / 1_000) -  0.000_105) < RPerl::EPSILON()  #   EXPECTED BEHAVIOR: true

    my number $foo = 0.105 / 1_000;
    my number $faa = 0.105 / 1_000;
    my number $bar = 0.000_105;
    my number $bat = 0.000_105;
         if (0.000_105 == 0.000_105)             { print 'true'; } else { print 'false'; }  #   EXPECTED BEHAVIOR: true
         if ((0.105 / 1_000) == (0.105 / 1_000)) { print 'true'; } else { print 'false'; }  #   EXPECTED BEHAVIOR: true
         if ($bar == $bat)                       { print 'true'; } else { print 'false'; }  #   EXPECTED BEHAVIOR: true
         if ($foo == $faa)                       { print 'true'; } else { print 'false'; }  #   EXPECTED BEHAVIOR: true
         if ($foo == $bar)                       { print 'true'; } else { print 'false'; }  # UNEXPECTED BEHAVIOR: false
    if (abs ($foo -  $bar) < RPerl::EPSILON())   { print 'true'; } else { print 'false'; }  #   EXPECTED BEHAVIOR: true

WARNING FOR ALL FLOATING-POINT NUMERIC OPERATORS:

Due to floating-point error, unexpected behavior may be experienced if a floating-point value is tested for exact equality with any other value.

Always use the floating-point epsilon value RPerl::EPSILON() to check for approximate equality instead of exact equality.

Section 2.1.11: Arithmetic Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Absolute Value

abs

Unary

Prefix

01

Left

Coming Soon

Natural Exponential Function

exp

Unary

Prefix

01

Non

Coming Soon

Exponent AKA Power

**

Binary

Infix

04

Right

Yes

Negative with Parentheses

-( )

Unary

Closed

05

Right

Yes

Multiply

*

Binary

Infix

07

Left

Yes

Divide

/

Binary

Infix

07

Left

Yes

Modulo AKA Modulus

%

Binary

Infix

07

Left

Yes

Add

+

Binary

Infix

08

Left

Yes

Subtract

-

Binary

Infix

08

Left

Yes

Natural Logarithm

log

Unary

Prefix

10

Non

Coming Soon

Square Root

sqrt

Unary

Prefix

10

Non

Coming Soon

Section 2.1.12: Trigonometry Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Arctangent-Divide

atan2

Binary

Prefix

01

Left

Coming Soon

Sine

sin

Unary

Prefix

10

Non

Coming Soon

Cosine

cos

Unary

Prefix

10

Non

Coming Soon

Section 2.1.13: Comparison (Relational & Equality) Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Less-Than

<

Binary

Infix

11

Non

Yes

Greater-Than

>

Binary

Infix

11

Non

Yes

Less-Than-Or-Equal

<=

Binary

Infix

11

Non

Yes

Greater-Than-Or-Equal

>=

Binary

Infix

11

Non

Yes

Equal

==

Binary

Infix

12

Non

Yes

Not-Equal

!=

Binary

Infix

12

Non

Yes

Three-Way Comparison AKA Spaceship

<=>

Binary

Infix

12

Non

Coming Soon

Section 2.1.14: Logic Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Logical Negation

!

Unary

Prefix

05

Right

Yes

Logical And

&&

Binary

Infix

15

Left

Yes

Logical Or

||

Binary

Infix

16

Left

Yes

Logical Negation

not

Unary

Prefix

22

Right

Yes

Logical And

and

Binary

Infix

23

Left

Yes

Logical Or

or

Binary

Infix

24

Left

Yes

Logical Xor

xor

Binary

Infix

24

Left

Yes

Section 2.1.15: Bitwise Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Bitwise Negation with Parentheses

~( )

Unary

Closed

05

Right

Yes

Bitwise Shift Left

<<

Binary

Infix

09

Left

Coming Soon

Bitwise Shift Right

>>

Binary

Infix

09

Left

Coming Soon

Bitwise And

&

Binary

Infix

13

Left

Coming Soon

Bitwise Or

|

Binary

Infix

14

Left

Coming Soon

Bitwise Xor

^

Binary

Infix

14

Left

Coming Soon

All code examples are shown using 64-bit integers; your results may vary depending upon your C++ compiler and hardware platform.

WARNING FOR ALL BITWISE OPERATORS:

Due to the difference between how integer and non-integer scalar values are stored in memory, you may experience unexpected or undefined behavior if a bitwise operator is passed any non-integer operands as input.

Only utilize bitwise operators with integer, unsigned_integer, or boolean operands.

    ~(1)      # good use of bitwise negation    operator
    12 << 2   # good use of bitwise shift left  operator
    13 >> 3   # good use of bitwise shift right operator

    my unsigned_integer $foo = 14;
    $foo & 4  # good use of bitwise and operator
    $foo | 5  # good use of bitwise  or operator
    $foo ^ 6  # good use of bitwise xor operator

    my number $bar = 21.12;
    ~($bar)         # UNEXPECTED BEHAVIOR: bad use of bitwise negation    operator
      $bar <<    7  # UNEXPECTED BEHAVIOR: bad use of bitwise shift left  operator
         8 >> $bar  # UNEXPECTED BEHAVIOR: bad use of bitwise shift right operator

    23.42 &   9   # UNEXPECTED BEHAVIOR: bad use of bitwise and operator
    23    ^ 1.1   # UNEXPECTED BEHAVIOR: bad use of bitwise xor operator

Also, due to the difference between how signed and unsigned integer values are stored in memory, both Perl's use integer; pragma configuration command as well as RPerl's integer and unsigned_integer data types must be utilized in correct combination, as described below. Perl relies on the use integer; pragma to determine numeric data types, while C++ relies on the actual data types provided by the software developers as part of each variable declaration. You may experience unexpected behavior if a bitwise operator is utilized with mismatching pragma and data types.

Each call to Perl's use integer; pragma applies to 1 entire RPerl source code file at a time, either 1 full *.pl program file or 1 full *.pm module file. If the use integer; pragma is in effect for a specific RPerl file, then all bitwise operators in said file must be provided with input operands which are signed (positive or negative) integers only, not unsigned integers or floating-point numbers or other data types. If use integer; is not in effect for an RPerl file, then all bitwise operators in said file must be provided with operands which are unsigned (non-negative) integers or booleans only, not signed integers or other data types.

The use integer; pragma also affects the results of all arithmetic and comparison operators by discarding the non-integer (fractional) portion of input operands, as if the floor operator were called to convert each floating-point number into an integer. Because of this, floating-point operators and signed integer bitwise operators must not be included in the same single RPerl source code file; to compensate, simply move all signed bitwise operators into their own separate RPerl *.pm module file which calls use integer;.

Please see the Perl documentation for more information about the use integer; pragma:

http://perldoc.perl.org/integer.html

    # good combination: no 'use integer;' pragma, 
    # unsigned_integer data types for bitwise negation operator, number data type for multiplication operation
    my unsigned_integer $foo = 5;
    my unsigned_integer $bar = ~($foo);  # $bar  = 18_446_744_073_709_551_610
    my number $quux = 21.12 * 42.23;     # $quux = 891.897_6

    # good combination: 'use integer;' pragma,
    # integer data types for both bitwise negation operator and multiplication operator
    use integer;
    my integer $foo = 5;
    my integer $bar = ~($foo);   # $bar  = -6
    my integer $quux = 21 * 42;  # $quux =  882

    # bad combination: no 'use integer;' pragma, 
    # integer data types for bitwise negation operator
    my integer $foo = 5;
    my integer $bar = ~($foo);   # UNEXPECTED BEHAVIOR: ($bar = 18_446_744_073_709_551_610) in Perl, but ($bar = -6) in C++

    # bad combination: 'use integer;' pragma,
    # unsigned_integer data types for bitwise negation operator, number data type for multiplication operator
    use integer;
    my unsigned_integer $foo = 5;
    my unsigned_integer $bar = ~($foo);  # UNEXPECTED BEHAVIOR: ($bar = -6) in Perl, but ($bar = 18_446_744_073_709_551_610) in C++
    my number $quux = 21.12 * 42.23;     # UNEXPECTED BEHAVIOR: ($quux = 882) in Perl, but ($quux = 891.897_6) in C++

Section 2.1.16: Miscellaneous Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Floor with Parentheses

POSIX::floor( )

Unary

Closed

01

Left

Coming Soon

Ceiling with Parentheses

POSIX::ceil( )

Unary

Closed

01

Left

Coming Soon

Separate Integer & Fraction Parts with Parentheses

POSIX::modf( )

Binary

Closed

01

Left

Coming Soon

Integer Part

int

Unary

Prefix

10

Non

Coming Soon

Random Number

rand

Nullary or Unary

Prefix

10

Non

Coming Soon

Random Seed

srand

Nullary or Unary

Prefix

10

Non

Coming Soon

Section 2.2: Strings (Text Data & Operators)

RPerl provides 2 text data types:

RPerl provides 3 delimiters for enclosing text data:

Perl 5 provides several built-in operators designed for use with text data, which can be organized into 7 general categories:

Section 2.2.1: Character Literals

The most memory-efficient text literal is character, which represents exactly zero characters or one character of information. A character may express the value of any single numeric digit (0, 1, 2, ..., 8, 9); letter (a, b, c, ..., y, z, A, B, C, ..., Y, Z ); or special ASCII character (!, #, *, +, etc). If the character literal has length zero, meaning it represents zero characters of information, then it is called the "empty character" and contains no data.

    ''           # INVALID: use q{} for empty character
    '0'          #   VALID
    'h'          #   VALID
    '+'          #   VALID
    '\n'         # INVALID: too many characters, use "\n" for newline character
    '-1'         # INVALID: too many characters
    'howdy23!'   # INVALID: too many characters

    ""           # INVALID: use q{} for empty character
    "0"          #   VALID
    "h"          #   VALID
    "+"          #   VALID
    "\n"         #   VALID: newline
    "-1"         # INVALID: too many characters & invalid use of double quotes
    "howdy23!"   # INVALID: too many characters & invalid use of double quotes

    q{}          #   VALID: empty
    q{0}         #   VALID
    q{h}         #   VALID
    q{+}         #   VALID
    q{\n}        # INVALID: too many characters, use "\n" for newline character
    q{-1}        # INVALID: too many characters
    q{howdy23!}  # INVALID: too many characters

Section 2.2.2: String Literals

Any text data more than 1 character in length must be represented by a string literal, which is comprised of any combination of valid character literal characters (numeric digits, letters, and special ASCII characters). Like the empty character, if a string literal has length zero then it is called the "empty string" and contains no data.

    ''           # INVALID: use q{} for empty string
    '0'          #   VALID
    'h'          #   VALID
    '+'          #   VALID
    '\n'         # INVALID: not a newline, use "\n" for string containing newline
    '\\n'        #   VALID: interpolated to become two characters (backslash, letter n)
    '-1'         #   VALID
    'howdy23!'   #   VALID

    ""           # INVALID: use q{} for empty string
    "0"          # INVALID: invalid use of double quotes, must contain newline or tab character(s)
    "h"          # INVALID: invalid use of double quotes, must contain newline or tab character(s)
    "+"          # INVALID: invalid use of double quotes, must contain newline or tab character(s)
    "\n"         #   VALID: interpolated to become newline character
    "-1"         # INVALID: invalid use of double quotes, must contain newline or tab character(s)
    "howdy23!"   # INVALID: invalid use of double quotes, must contain newline or tab character(s)

    q{}          #   VALID: empty string
    q{0}         #   VALID
    q{h}         #   VALID
    q{+}         #   VALID
    q{\n}        # INVALID: not a newline, use "\n" for string containing newline
    q{\\n}       #   VALID: interpolated to become two characters (backslash, letter n)
    q{-1}        #   VALID
    q{howdy23!}  #   VALID

Section 2.2.3: Single Quotes

Text literals enclosed in single quotes are the simplest and most common case in RPerl.

Single-quoted text literals are not "interpolated", which means the literal's data contents are not changed by Perl or RPerl in any way, except for the extra-special double backslash \\ as described below. Because single quotes do not activate string interpolation, you can not use a single-quoted string literal to represent special characters such as newline or tab.

Do not use single quotes to represent a newline or tab character, use double quotes "\n" or "\t" instead.

Do not use single quotes to represent an empty character or empty string, use q quotes q{} instead.

In normal Perl, single backslash characters \ are used to create special characters called "escape sequences", the most common of which are the well-known newline \n and tab \t escape sequences. Each valid escape sequence actually counts as only one character of computer data, even though it is represented to humans by 2 or more typed characters, so a single escape sequence may be utilized as either a character text literal or a string text literal. (Thus, "\n" and "\t" may both be utilized as either a character or string in RPerl, but only when using double quotes as discussed in the following section.)

In single-quoted string literals, the only escape sequence supported by RPerl is the double backslash \\, so the string literal '\\' is interpolated to mean only one single backslash character \. To represent two backslash characters \\, utilize two double backslash escape sequences in a row '\\\\'; for three backslashes \\\ utilize three escape sequences '\\\\\\', and so forth.

Because RPerl only accepts double backslashes (not single backslashes) within single quotes, RPerl thus does not accept any odd number of consecutive backslash characters within single quotes. For example, two or four backslashes in a row are supported, but one or three or five directly adjacent backslashes are not supported.

In normal Perl, the backslash single quote \' escape sequence may be used to include a single quote character ' within a single-quoted text literal. As stated above, RPerl only supports the double backslash \\ escape sequence within single quotes, so the backslash single quote \' escape sequence is thus not supported. Use double quotes "'" or q quotes q{'} to represent a single quote ' character in an RPerl string literal.

Single-quoted text literals must not contain:

Single-quoted text literals may contain:

    ''      # INVALID: empty string
    ' '     #   VALID: single space
    'a'     #   VALID: single letter
    '\'     # INVALID: single backslash

    '   '   #   VALID: three spaces
    ' ' '   # INVALID: single quote within single quotes
    '\' '   # INVALID: backslash single quote escape sequence, also single backslash

    ' a '   #   VALID: space, letter, space
    '"a}'   #   VALID: double quote, letter, right brace
    '\a}'   # INVALID: single backslash       not interpolated as audible bell (alarm beep) escape sequence
    '\n}'   # INVALID: single backslash       not interpolated as newline                   escape sequence
    '\\}'   #   VALID: double backslash           interpolated as one backslash character, right brace
    '\\\'   # INVALID: odd  number of backslashes 
    '\\\\'  #   VALID: even number of backslashes interpolated as half as many backslash characters

BEST PRACTICES

  • Use single-quoted text literals whenever possible.
    'n'      #     BEST PRACTICE
    "n"      # NOT BEST PRACTICE: double quotes not needed
    q{n}     # NOT BEST PRACTICE:      q quotes not needed

    '1atx'   #     BEST PRACTICE
    "1atx"   # NOT BEST PRACTICE: double quotes not needed
    q{1atx}  # NOT BEST PRACTICE:      q quotes not needed

    '\\tx'   #     BEST PRACTICE
    "\\tx"   # NOT BEST PRACTICE: double quotes    invalid, extra backslash
    q{\\tx}  # NOT BEST PRACTICE:      q quotes not needed

Section 2.2.4: Double Quotes

Text literals enclosed in double quotes are fully interpolated in normal Perl, and are only used for trivial interpolation of strings containing the newline "\n" or tab "\t" escape sequences in RPerl. All double-quoted strings in RPerl must contain at least one newline or tab special character.

In addition to escape sequences, string interpolation in normal Perl is also triggered by finding either the dollar sign $ or "at sign" @ characters inside of a double-quoted string literal. Because RPerl does not support string interpolation, double-quoted string literals must not contain the $ or @ characters.

Double-quoted string literals must not contain any backslash characters, other than those used in newline \n and tab \t escape sequences, and thus can not represent a single backslash character \; use single quotes '\\' or q quotes q{\\} double backslash escape sequences instead.

As with single quotes, in normal Perl the backslash double quote \" escape sequence may be used to include a double quote character " within a double-quoted text literal. As stated above, RPerl only supports the newline \n and tab \t escape sequences within double quotes, so the backslash double quote \" escape sequence is thus not supported. Use single quotes '"' or q quotes q{"} to represent a double quote " character in an RPerl string literal.

Double-quoted text literals must not contain:

Double-quoted text literals must contain 1 or more:

Double-quoted text literals may contain:

    ""      # INVALID: empty string
    " "     #   VALID: single space
    "a"     #   VALID: single letter
    "\"     # INVALID: extra  backslash,                                                                     only \n and \t supported

    "   "   #   VALID: three spaces
    " " "   # INVALID: double quote within double quotes
    "\" "   # INVALID: backslash double quote escape sequence, also single backslash

    " a "   #   VALID: space, letter, space
    "'a}"   #   VALID: single quote, letter, right brace
    "\a}"   # INVALID: single backslash           interpolated as audible bell (alarm beep) escape sequence, only \n and \t supported
    "\n}"   #   VALID: single backslash           interpolated as newline                   escape sequence, right brace
    "\\}"   # INVALID: extra  backslashes,                                                                   only \n and \t supported
    "\\\"   # INVALID: extra  backslashes,                                                                   only \n and \t supported 
    "\\\\"  # INVALID: extra  backslashes,                                                                   only \n and \t supported

BEST PRACTICES

  • Use double-quoted text literals to contain newline \n and tab \t characters only, not other normal characters.
  • To represent a mixture of normal characters with newline and/or tab characters, enclose the normal characters in single quotes, enclose the newline and tab characters in double quotes, and use the dot . "string concatenation" operator to append one string literal to the other. (Please see "Section 2.2.6: Editing Operators" for more info about string concatenation.)
    "\n"        #     BEST PRACTICE:     newline         only
    "\t"        #     BEST PRACTICE:                 tab only
    "\t\n\t"    #     BEST PRACTICE:     newline and tab only

    "a\n"       # NOT BEST PRACTICE: not newline and tab only
    'a' . "\n"  #     BEST PRACTICE:     newline         only, additional characters in single quotes

    "\tx"       # NOT BEST PRACTICE: not newline and tab only
    "\t" . 'x'  #     BEST PRACTICE:                 tab only, additional characters in single quotes

    "a\tx\n"                 # NOT BEST PRACTICE: not newline and tab only
    'a' . "\t" . 'x' . "\n"  #     BEST PRACTICE:     newline and tab only, additional characters in single quotes

Section 2.2.5: q Quotes

Text literals enclosed in "q quotes" begin with lowercase letter q and left curly brace characters q{, and end with the right curly brace } character. You must use q quotes to represent empty text q{} literals, which contain no characters.

Normal Perl supports q-quoted string literals using delimiters other than curly braces, as well as "qq quotes" which provide string interpolation in the same way as double-quoted strings. RPerl's existing string quoting mechanisms cover all non-interpolated use cases, so RPerl does not support the additional qq quotes or non-curly-brace q quotes, because TDNNTBMTOWTDI.

q-quoted literals behave exactly the same as single-quoted literals, other than the empty string q{} and the difference in delimiters.

q-quoted text literals must not contain:

q-quoted text literals may contain:

    q{}      #   VALID: empty string
    q{ }     #   VALID: single space
    q{a}     #   VALID: single letter
    q{\}     # INVALID: single backslash

    q{   }   #   VALID: three spaces
    q{ } }   # INVALID: right brace within q quotes
    q{\} }   # INVALID: backslash right brace escape sequence, also single backslash

    q{ a }   #   VALID: space, letter, space
    q{"a'}   #   VALID: double quote, letter, single quote
    q{\a'}   # INVALID: single backslash       not interpolated as audible bell (alarm beep) escape sequence
    q{\n'}   # INVALID: single backslash       not interpolated as newline                   escape sequence
    q{\\'}   #   VALID: double backslash           interpolated as one backslash character, single quote
    q{\\\}   # INVALID: odd  number of backslashes 
    q{\\\\}  #   VALID: even number of backslashes interpolated as half as many backslash characters

BEST PRACTICES

  • Use q-quoted text literals to represent empty text literals only.
    ''      # NOT BEST PRACTICE: single quotes invalid, empty string
    ""      # NOT BEST PRACTICE: double quotes invalid, empty string
    q{}     #     BEST PRACTICE

    '0gnb'   #     BEST PRACTICE
    "0gnb"   # NOT BEST PRACTICE: double quotes not needed
    q{0gnb}  # NOT BEST PRACTICE:      q quotes not needed

    '\\nx'   #     BEST PRACTICE
    "\\nx"   # NOT BEST PRACTICE: double quotes    invalid, extra backslash
    q{\\nx}  # NOT BEST PRACTICE:      q quotes not needed

Section 2.2.6: Editing Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Substring

substr

Variadic

Prefix

01

Left

Coming Soon

Repeat

x

Binary

Infix

07

Left

Coming Soon

Concatenate

.

Binary

Infix

08

Left

Yes

Length

length

Unary

Prefix

10

Non

Coming Soon

Section 2.2.7: Case Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Lowercase

lc

Unary

Prefix

10

Non

Coming Soon

Lowercase First Character

lcfirst

Unary

Prefix

10

Non

Coming Soon

Uppercase

uc

Unary

Prefix

10

Non

Coming Soon

Uppercase First Character

ucfirst

Unary

Prefix

10

Non

Coming Soon

Section 2.2.8: Comparison (Relational & Equality) Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Less-Than

lt

Binary

Infix

11

Non

Coming Soon

Greater-Than

gt

Binary

Infix

11

Non

Coming Soon

Less-Than-Or-Equal

le

Binary

Infix

11

Non

Coming Soon

Greater-Than-Or-Equal

ge

Binary

Infix

11

Non

Coming Soon

Equal

eq

Binary

Infix

12

Non

Coming Soon

Not Equal

ne

Binary

Infix

12

Non

Coming Soon

Three-Way Comparison

cmp

Binary

Infix

12

Non

Coming Soon

Section 2.2.9: Search Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Index

index

Variadic

Prefix

01

Left

Coming Soon

Reverse Index

rindex

Variadic

Prefix

01

Left

Coming Soon

Section 2.2.10: Formatting Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

String Formatted Print

sprintf

Variadic

Prefix

01

Left

Coming Soon

Quote Meta

quotemeta

Unary

Prefix

10

Non

Coming Soon

Section 2.2.11: Base Conversion Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Chr

chr

Unary

Prefix

01

Left

Coming Soon

Hex

hex

Unary

Prefix

10

Non

Coming Soon

Oct

oct

Unary

Prefix

10

Non

Coming Soon

Ord

ord

Unary

Prefix

10

Non

Coming Soon

Section 2.2.12: Miscellaneous Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Crypt

crypt

Binary

Prefix

01

Left

Coming Soon

Section 2.3: RPerl´s Built-In Warnings & Errors

Section 2.4: Scalar Variables

An RPerl "expression" is any general-purpose language component which either returns a value or is a literal value itself.

An RPerl "statement" is any general-purpose language component which performs some action(s).

An RPerl "named operator" is any of the 220+ Perl named operators, although RPerl only supports the low-magic forms of each operator.

An RPerl "operation" is the equivalent of a single sentence in human language, and may be either an expression followed by a ; semicolon punctuation character, or a named operator followed by a semicolon, or a statement.

The = equal sign is the assignment operator, used to set the variable on its left to store the value of the expression on its right.

Perl's my keyword is used to declare a new variable, and optionally initialize it to a starting value when combined with the = assignment operator.

Normal Perl does not support specific data types, so in Perl one variable named $foo may be initialized with a numeric value, then the same $foo variable may be changed to hold a string value without any warning or error.

    my $foo = 23;
    $foo = 'twenty-three';  # just fine in normal Perl

On the other hand, RPerl requires the use of data types for each and every variable.

    my $foo = 23;  # error in RPerl, all modes

    my number $foo = 23;
    $foo = 'twenty-three';  # error in RPerl, compiled (non-test) modes, assigning string literal to number variable

    my number $foo = 23;
    $foo = 42;  # just fine in RPerl

Normal Perl provides a special literal value undef, along with a built-in function named defined which is used to test if a variable contains the special undef value. RPerl does not support undef or defined, because C++ does not fully support the concept of undefined values, and RPerl's high-speed components are written using C++.

Data types make your code much more readable and much, much faster. Learn to love data types. Now.

Section 2.4.x: Choosing Good Variable Names

Section 2.4.x: Bool Data Type

The most efficient data type is boolean, which stores a single "bit" (binary digit) of information. A boolean may only hold the values of exactly 0 or 1.

    my boolean $foo = 0;     # fine
    my boolean $bar = 1;     # fine
    my boolean $baz = -1.5;  # error in RPerl, compiled (non-test) modes

Section 2.4.x: Integer Data Type

The next most efficient data type is integer, which stores a single whole (non-decimal) number. An integer may hold any positive or negative whole number, within the data size limits of your operating system and computer hardware.

    my integer $foo  = -23;     # fine
    my integer $bar  = 0;       # fine
    my integer $baz  = 42_230;  # fine
    my integer $bax  = 42.1;    # error in RPerl, compiled (non-test) modes
    my integer $quux = -999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999_999;  # likely error or data corruption, outside limits

Section 2.4.x: Number Data Type

The number data type stores a single floating-point (decimal) number, and may hold any real number within your computer's limits.

    my number $foo  = -23.42;     # fine
    my number $bar  = 0.000_001;  # fine
    my number $baz  = 42.23;      # fine
    my number $bax  = 42;         # fine
    my number $quux = -4_123.456_789_123_456_789_123_456_789_123_456_789_123_456_789_123_456_789_123_456;  # likely error or data loss, outside limits

Section 2.4.x: Type Conversion

To convert from one data type to another, we use the RPerl type conversion subroutines, shown below for numeric types only:

    my integer $foo = 23;
    my number $bar  = $foo;  # error in RPerl, compiled (non-test) modes, type mismatch

    my integer $foo = 23;
    my number $bar  = integer_to_number($foo);  # fine, $bar is now 23.0

    my number $foo  = 23.42;
    my integer $bar = $foo;  # error in RPerl, compiled (non-test) modes, type mismatch

    my number $foo  = 23.42;
    my integer $bar = number_to_integer($foo);  # fine, $bar is now 23

Section 2.4.x Scope, Type, Name, Value

START HERE: continue editing & adding content START HERE: continue editing & adding content START HERE: continue editing & adding content

The "scope" of a variable is either local using the my keyword, or global using the our keyword. Local variables are only usable within their own enclosing code block such as a conditional (section xxx), loop (xxx), or subroutine (chapter 4).

and global variables are usable within any code block accessible by the Perl interpreter or (RPerl compiler).

Except for certain special circumstances, all variables in RPerl are locally-scoped using my.

Section 2.4.x: Binary Assignment Operators

    OP19_VARIABLE_ASSIGN_BY   = /(\+=|-=|\*=|\/=)/            # precedence 19 infix: add assign '+=', subtract assign '-=', multiply assign '*=', divide assign '/='
    %token OP19_VARIABLE_ASSIGN_BY   = /(\.=)/        # precedence 19 infix: string concatenation assign '.='

Section 2.4.x: Increment & Decrement Operators

Name

Symbol

Arity

Fixity

Precedence

Associativity

Supported

Pre-Increment

++

Unary

Prefix

03

Non

Yes

Post-Increment

++

Unary

Postfix

03

Non

Yes

Pre-Decrement

--

Unary

Prefix

03

Non

Yes

Post-Decrement

--

Unary

Postfix

03

Non

Yes

    # NEED ADD EXAMPLES
    ++$i  # 0

Section 2.4.x: Chomp & Chop Operators

Section 2.5: Constant Data

Section 2.6: Output With print

Section 2.7: The if Control Structure

Section 2.8: Getting User Input

Section 2.10: The while Control Structure

Section 2.x: Exercises

1. XXXYYYZZZ [ XYZ mins ]


CHAPTER 3: LISTS & ARRAYS

Section 3.x.x: SSE Operators

    OP08_MATH_ADD_SUB         = /(sse_add|sse_sub)/    # precedence 08 infix: SSE add 'sse_add', SSE subtract 'sse_sub'
    OP07_MATH_MULT_DIV_MOD    = /(sse_mul|sse_div)/  # precedence 07 infix: SSE multiply 'sse_mul', SSE divide 'sse_div'


CHAPTER 4: SUBROUTINES


CHAPTER 5: INPUT & OUTPUT


CHAPTER 6: HASHES


CHAPTER 7: REGULAR EXPRESSIONS


CHAPTER 8: REGULAR EXPRESSIONS MATCHING


CHAPTER 9: REGULAR EXPRESSIONS PROCESSING


CHAPTER 10: CONTROL STRUCTURES


CHAPTER 11: CLASSES, PACKAGES, MODULES, LIBRARIES


CHAPTER 12: FILE TESTS

Section 12.x.x: File Test Operators

    %token OP10_NAMED_UNARY_SCOLON   = /(-A;|-B;|-C;|-M;|-O;|-R;|-S;|-T;|-W;|-X;|-b;|-c;|-d;|-e;|-f;|-g;|-k;|-l;|-o;|-p;|-r;|-s;|-t;|-u;|-w;|-x;|-z;)/


CHAPTER 13: DIRECTORY OPERATIONS


CHAPTER 14: STRINGS & SORTING


CHAPTER 15: SMART MATCHING & GIVEN-WHEN


CHAPTER 16: PROCESS MANAGEMENT


CHAPTER 17: SOME ADVANCED TECHNIQUES

Section 17.x.x: UNSORTED Operators

# REGEX %token OP01_NAMED_SCOLON = /(m;|pos;|qr;|s;|study;|tr;|y;

# FORMAT %token OP01_NAMED_SCOLON = /(format;|formline;|write;

# PACK / UNPACK %token OP01_NAMED_SCOLON = /(pack;|unpack;|vec;|

# UNSORTED %token OP01_NAMED_SCOLON = /(accept;|bind;|binmode;|bless;|break;|chmod;|chomp;|chop;|chown;|closedir;|connect;|continue;|dbmclose; |dbmopen;|default;|dump;|each;|endgrent;|endhostent;|endnetent;|endprotoent;|endpwent;|endservent;|eof;|evalbytes;|exec;|fcntl;|fileno;|flock;|fork; |getc;|getgrent;|getgrgid;|getgrnam;|gethostbyaddr;|gethostent;|getlogin;|getnetbyaddr;|getnetent;|getpeername;|getppid;|getpriority; |getprotobynumber;|getprotoent;|getpwent;|getpwnam;|getpwuid;|getservbyname;|getservbyport;|getservent;|getsockname;|getsockopt;|given;|grep;|ioctl;|join; |keys;|kill;|link;|listen;|local;|map;|mkdir;|msgctl;|msgget;|msgrcv;|msgsnd;|opendir;|pipe;|pop;|prototype;|push;|qx;|read;|readdir; |readline;|readpipe;|recv;|rename;|reset;|reverse;|rewinddir;|say;|seek;|seekdir;|select;|semctl;|semget;|semop;|send;|setgrent;|sethostent;|setnetent; |setpgrp;|setpriority;|setprotoent;|setpwent;|setservent;|setsockopt;|shift;|shmctl;|shmget;|shmread;|shmwrite;|shutdown;|socket;|socketpair;|sort;|splice;|split; |state;|symlink;|syscall;|sysopen;|sysread;|sysseek;|system;|syswrite;|tell;|telldir;|tie;|tied;|time;|times;|truncate;|unless;|unlink; |unshift;|untie;|until;|utime;|values;|vec;|wait;|waitpid;|wantarray;|warn;|when;)/

    %token OP10_NAMED_UNARY_SCOLON   = /(alarm;|caller;|chdir;|chroot;|defined;|delete;|do;|eval;|exists;|gethostbyname;|getnetbyname;|getpgrp;|getprotobyname;|glob;
    |gmtime;|goto;|localtime;|lock;|lstat;|readlink;|ref;|require;|rmdir;|scalar;|sleep;|stat;|umask;)/


APPENDIX A: EXERCISE ANSWERS

Chapter 1, Exercise 1

This exercise is commonly used as the first task for new programmers, or for programmers who are learning a new language.
The goal of this exercise is to become familiar with the boilerplate (often-repeated template) RPerl HEADER and CRITICS code sections, as well as the basic print command.
The first line, starting with #! and called a "shebang", tells the operating system to run this program using Perl.
The 4 lines in the HEADER section tell Perl to run this program using RPerl, and the $VERSION number may be incremented for each update to this file.
The line in the CRITICS section, starting with ##, tells RPerl to allow hard-coded numeric values (not used in this program), as well as the print operator.
The last line, in the OPERATIONS section, calls the print operator to simply display the text "Hello, world!" followed by a newline character, combined into a single string value by the . (single dot) string concatenation operator.
All other lines beginning with # are comments and, along with blank lines, may be safely ignored or removed.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 1, Exercise 1
    # Print "Hello, world!"; the classic first program for new programmers

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator

    # [[[ OPERATIONS ]]]
    print 'Hello, world!' . "\n";

Example execution and output:

    $ rperl -t LearningRPerl/Chapter1/exercise_1-hello_world.pl
    Hello, world!


Chapter 1, Exercise 2

The goal of this exercise is to become familiar with the rperl command.

Example execution and output for 2a and 2b:

    $ rperl -?
    Usage:
                rperl [OPTIONS] input_program_0.pl [input_program_1.pl input_program_2.pl ...]
                rperl [OPTIONS] MyClassFoo.pm [MyClassBar.pm MyClassBat.pm ...]
                rperl [OPTIONS] input_program_0.pl MyClassFoo.pm [input_program_1.pl ... MyClassBar.pm ...]
    
    Options:
        --help _OR_ -h _OR_ -?
                 Print a brief help message for command-line usage.
    
        --version _OR_ -v
        --vversion _OR_ -vv
                 Print version number and copyright information.
                 Repeat as 'vv' for more technical information, similar to `perl -V` configuration summary option.
                 Lowercase 'v' not to be confused with uppercase 'V' in 'Verbose' option below.
    
        --dependencies _OR_ -d
        --nodependencies _OR_ -nod
                 Follow and compile dependencies, or not.
                 Enabled by default, equivalent to '--mode dependencies=ON' option.
                 Lowercase 'd' not to be confused with uppercase 'D' in 'Debug' option below.
                 WARNING: Disabling dependencies will likely cause errors or undefined behavior.
    
        --infile=MyFile.pm _OR_ -i=MyFile.pm
                 Specify input file, may be repeated for multiple input files.
                 Option prefix '--infile' may be entirely omitted.
                 Option prefix MUST be omitted to specify wildcard for multiple input files.
    
        --outfile=MyFile _OR_ -o=MyFile
                 Specify output file prefix, may be repeated for multiple output files.
                 RPerl *.pm input file with PERL ops will create MyFile.pmc output file.
                 RPerl *.pl input file with PERL ops will create my_file (or my_file.exe) & my_file.pmc output files.
                 RPerl *.pm input file with CPP ops will create MyFile.pmc, MyFile.cpp, & MyFile.h output files.
                 RPerl *.pl input file with CPP ops will create myfile (or myfile.exe on Windows), MyFile.pmc, MyFile.cpp, & MyFile.h output files.
                 Option may be entirely omitted, 'MyFile.*' input file will default to 'MyFile.*' out.
    
        --mode ops=PERL _OR_ -m ops=PERL
        --mode ops=CPP _OR_ -m ops=CPP
                 Specify operations mode, CPP by default.
                 If set to PERL, generate Perl operations in the source code output file(s).
                 If set to CPP, generate C++ operations in the source code output file(s).
                 PERL ops mode forces PERL types mode & PARSE or GENERATE compile mode; PERLOPS_PERLTYPES is test mode, does not actually compile.
    
        --mode types=PERL _OR_ -m types=PERL
        --mode types=CPP _OR_ -m types=CPP
        --mode types=DUAL _OR_ -m types=DUAL
                 Specify data types mode, CPP by default.
                 If set to PERL, generate Perl data types in the source code output file(s).
                 If set to CPP, generate C++ data types in the source code output file(s).
                 If set to DUAL, generate both Perl and C++ data types in the source code output file(s).
                 DUAL mode allows generate-once-compile-many types, selected by '#define __FOO__TYPES' in lib/rperltypes_mode.h or `gcc -D__FOO__TYPES` manual subcompile option.
    
        --mode check=OFF _OR_ -m check=OFF
        --mode check=ON _OR_ -m check=ON
        --mode check=TRACE _OR_ -m check=TRACE
                 Specify data type checking mode, TRACE by default.
                 If set to OFF, do not perform dynamic type checking, only built-in C++ static type checking.
                 If set to ON, perform dynamic type checking in addition to built-in C++ static type checking.
                 If set to TRACE, perform dynamic type checking in addition to built-in C++ static type checking, with subroutine-and-variable trace information.
    
        --mode dependencies=OFF _OR_ -m dependencies=OFF
        --mode dependencies=ON _OR_ -m dependencies=ON
                 Specify dependencies mode, ON by default.
                 If set to OFF, do not search for or compile dependencies.
                 If set to ON, recursively search for dependencies and subdependencies, include as additional input file(s).
    
        --mode uncompile=OFF _OR_ -m uncompile=OFF
        --mode uncompile=SOURCE _OR_ -m uncompile=SOURCE
        --mode uncompile=BINARY _OR_ -m uncompile=BINARY
        --mode uncompile=INLINE _OR_ -m uncompile=INLINE
        --mode uncompile=SOURCE_BINARY _OR_ -m uncompile=SOURCE_BINARY
        --mode uncompile=SOURCE_BINARY_INLINE _OR_ -m uncompile=SOURCE_BINARY_INLINE
                 Specify uncompile mode, OFF by default.
                 If set to SOURCE, delete all generated C++ output source code (not subcompiled) files: *.cpp, *.h, *.pmc
                 If set to BINARY, delete all generated C++ output binary (subcompiled) files: *.o, *.a, *.so, *.exe, non-suffixed executables
                 If set to INLINE, delete all generated C++ output Inline::CPP files: _Inline/ directory
                 If set to SOURCE_BINARY, delete both SOURCE and BINARY files.
                 If set to SOURCE_BINARY_INLINE, delete SOURCE, BINARY, and INLINE files.
                 For *.pm Perl module input files, BINARY and INLINE are equivalent.
    
        --mode compile=PARSE _OR_ -m compile=PARSE
        --mode compile=GENERATE _OR_ -m compile=GENERATE
        --mode compile=SUBCOMPILE _OR_ -m compile=SUBCOMPILE
                 Specify compile mode, SUBCOMPILE by default.
                 If set to PARSE, begin with RPerl input source code file(s), and end with RPerl abstract syntax tree output data structure.
                 If set to GENERATE, begin with RPerl input source code file(s), and end with RPerl and/or C++ output source code file(s).
                 If set to SUBCOMPILE, begin with RPerl input source code file(s), and end with C++ output binary file(s).
    
        --mode subcompile=OFF _OR_ -m subcompile=OFF
        --mode subcompile=ASSEMBLE _OR_ -m subcompile=ASSEMBLE
        --mode subcompile=ARCHIVE _OR_ -m subcompile=ARCHIVE
        --mode subcompile=SHARED _OR_ -m subcompile=SHARED
        --mode subcompile=STATIC _OR_ -m subcompile=STATIC
        --mode subcompile=DYNAMIC _OR_ -m subcompile=DYNAMIC
                 Specify subcompile mode, DYNAMIC by default.
                 If set to ASSEMBLE, generate *.o object binary output file(s).
                 If set to ARCHIVE, generate *.a object archive binary output file(s).
                 If set to SHARED, generate *.so shared object binary output file(s).
                 If set to STATIC, generate statically-linked *.exe or non-suffixed executable binary output file(s).
                 If set to DYNAMIC, generate dynamically-linked *.exe or non-suffixed executable binary output file(s).
    
        --mode CXX=/path/to/compiler _OR_ -m CXX=/path/to/compiler
                 Specify path to C++ compiler for use in subcompile modes, 'g++' by default.
    
        --mode execute=OFF _OR_ -m execute=OFF
        --mode execute=ON _OR_ -m execute=ON
                 Specify execute mode, ON by default.
                 If set to OFF, do not load or run any user-supplied program(s).
                 If set to ON with one *.pl Perl program input file, load and run the program.
                 If set to ON with more than one *.pl Perl program input file, do not load or run any programs.
    
        --mode label=OFF _OR_ -m label=OFF
        --mode label=ON _OR_ -m label=ON
                 Specify source section label mode, ON by default.
                 If set to OFF, generate minimal output source code, may save disk space.
                 If set to ON, generate some informative labels in output source code, may be more human-readable.
    
        --uncompile _OR_ -u
        --nouncompile _OR_ -nou
        --uuncompile _OR_ -uu
        --nouuncompile _OR_ -nouu
        --uuuncompile _OR_ -uuu
        --nouuncompile _OR_ -nouuu
                 Uncompile (delete C++ source code and/or binary output files), or not.
                 Repeat as 'uu' and 'uuu' for more thorough file removal.
                 Do not confuse uncompile with decompile (recreate RPerl source code from C++ source code or binary output files), which does not currently exist.
                 '-u' equivalent to '--mode uncompile=SOURCE --mode compile=OFF --mode execute=OFF' options.
                 '-uu' equivalent to '--mode uncompile=SOURCE_BINARY --mode compile=OFF --mode execute=OFF' options.
                 '-uuu' equivalent to '--mode uncompile=SOURCE_BINARY_INLINE --mode compile=OFF --mode execute=OFF' options.
                 Disabled by default.
    
        --compile _OR_ -c
        --nocompile _OR_ -noc
                 Generate & subcompile C++ source code, or not.
                 Enabled by default, equivalent to '--mode compile=SUBCOMPILE' option.
    
        --execute _OR_ -e
        --noexecute _OR_ -noe
                 Run input code after optional compile, or not.
                 Enabled by default for *.pl program input files, always disabled for *.pm module input files or multiple input files.
                 Equivalent to '--mode execute=ON' option.
    
        --Verbose _OR_ -V
        --noVerbose _OR_ -noV
                 Include additional user information in output, or not.
                 If enabled, equivalent to `export RPERL_VERBOSE=1` shell command.
                 Disabled by default.
                 Uppercase 'V' not to be confused with lowercase 'v' in 'version' option above.
    
        --Debug _OR_ -D
        --noDebug _OR_ -noD
                 Include system diagnostic information in output, or not.
                 If enabled, equivalent to `export RPERL_DEBUG=1` shell command.
                 Disabled by default.
                 Uppercase 'D' not to be confused with lowercase 'd' in 'dependencies' option above.
    
        --Warnings _OR_ -W
        --noWarnings _OR_ -noW
                 Include system warnings in output, or not.
                 Enabled by default, equivalent to `export RPERL_WARNINGS=0` shell command.
    
        --test _OR_ -t
                 Test mode: Perl ops, Perl types, Parse & Generate (no Save or Compile)
                 If enabled, equivalent to '--mode ops=PERL --mode types=PERL --mode compile=GENERATE' options.
                 Disabled by default.
    
        --assemble
                 Assemble subcompile mode, output *.o object file(s).
                 If enabled, equivalent to '--mode subcompile=ASSEMBLE' option or `gcc -c` manual subcompile option.
                 Disabled by default.
    
        --archive
                 Archive subcompile mode, output *.a object archive file(s).
                 If enabled, equivalent to '--mode subcompile=ARCHIVE' option or `gcc -c` followed by `ar` manual subcompile command.
                 Disabled by default.
    
        --shared
                 Archive subcompile mode, output *.so shared object file(s).
                 If enabled, equivalent to '--mode subcompile=SHARED' option or `gcc -shared` manual subcompile command.
                 Disabled by default.
    
        --static
        --nostatic
                 Static subcompile mode, output *.exe or non-suffixed statically-linked executable file(s).
                 If disabled, equivalent to '--mode subcompile=DYNAMIC' option or `gcc` manual subcompile command.
                 If enabled, equivalent to '--mode subcompile=STATIC' option or `gcc -static` manual subcompile command.
                 Disabled by default.
    
        --CXX=/path/to/compiler
                 Specify path to C++ compiler, equivalent to '--mode CXX=/path/to/compiler' or 'CXX' manual Makefile option.

Example execution and output for 2c and 2d:

    $ rperl -t -V LearningRPerl/Chapter1/exercise_1-hello_world.pl 
    Verbose Flag:       1
    Debug Flag:         0
    Test Flag:          1
    Input File:         LearningRPerl/Chapter1/exercise_1-hello_world.pl
    Output File(s):     LearningRPerl/Chapter1/exercise_1-hello_world  
    Modes:              ops => PERL, types => PERL, check => TRACE, compile => GENERATE, execute => ON, label => ON

    DEPENDENCIES:       Follow & find all deps...    0 found.
    PARSE PHASE 0:      Check     Perl syntax...        done.
    PARSE PHASE 1:      Criticize Perl syntax...        done.
    PARSE PHASE 2:      Parse    RPerl syntax...        done.
    GENERATE:           Generate RPerl syntax...        done.
    EXECUTE:            Run code...

    Hello, world!


    $ rperl -t -D LearningRPerl/Chapter1/exercise_1-hello_world.pl 
    in rperl, have $RPerl::DEBUG = 1
    in rperl, have $RPerl::VERBOSE = 0
    Hello, world!


    $ rperl -t -V -D LearningRPerl/Chapter1/exercise_1-hello_world.pl 
    Verbose Flag:       1
    Debug Flag:         1
    Test Flag:          1

    in rperl, have $RPerl::DEBUG = 1
    in rperl, have $RPerl::VERBOSE = 1
    Input File:         LearningRPerl/Chapter1/exercise_1-hello_world.pl
    Output File(s):     LearningRPerl/Chapter1/exercise_1-hello_world  
    Modes:              ops => PERL, types => PERL, check => TRACE, compile => GENERATE, execute => ON, label => ON

    DEPENDENCIES:       Follow & find all deps...    0 found.
    PARSE PHASE 0:      Check     Perl syntax...        done.
    PARSE PHASE 1:      Criticize Perl syntax...        done.
    PARSE PHASE 2:      Parse    RPerl syntax...        done.
    GENERATE:           Generate RPerl syntax...        done.
    EXECUTE:            Run code...

    Hello, world!

Of the above 3 commands executed for 2c and 2d, the first includes normal output plus additional verbose output; the second includes normal output plus additional debugging output (minimal in this simple case); and the third includes normal output plus both verbose and debugging output.


Chapter 1, Exercise 3

The goal of this exercise is to become familiar with basic variables and arithmetic.
The shebang line, HEADER section, and first line in the CRITICS section are the same boilerplate as the previous exercise.
The second line in the CRITICS section tells RPerl to allow the $ (dollar) character, among others, to be displayed using the print operator.
The first 3 lines in the OPERATIONS section each declare a new variable; $foo and $bar each hold an integer (non-floating-point) numeric value, while $baz holds a number (floating-point) value.
The $foo and $bar variables receive their values from hard-coded numeric values being operated upon by the addition + and multiplication * operators, respectively; the $baz and $zab variables receive their values from the the $foo and $bar variables being operated upon by the division / operator. The to_number() type conversion subroutine is necessary for the C++ compiler to use floating-point arithmetic instead of integer arithmetic on the division / operators, without it we would receive the truncated integer value of 58 in $baz, for example. We will receive the correct floating-point answers if we call to_number() on either $bar (as shown), or $foo, or both; in other words, at least one of the input operands for each operator must be passed through to_number().
The last 4 lines call the print operator to display the names of each variable; followed by each variable's respective value, converted from number to underscore-formatted string via the RPerl type conversion subroutine to_string(); followed by a newline character.

    #!/usr/bin/perl
    
    # Learning RPerl, Chapter 1, Exercise 3
    # Foo Bar Arithmetic Example
    
    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;
    
    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(RequireInterpolationOfMetachars)  # USER DEFAULT 2: allow single-quoted control characters & sigils
    
    # [[[ OPERATIONS ]]]
    my integer $foo = 21 + 12;
    my integer $bar = 23 * 42;
    my number  $baz = to_number($bar) / $foo;
    my number  $zab = to_number($foo) / $bar;
    print 'have $foo = ' . to_string($foo) . "\n";
    print 'have $bar = ' . to_string($bar) . "\n";
    print 'have $baz = ' . to_string($baz) . "\n";
    print 'have $zab = ' . to_string($zab) . "\n";

Example execution and output:

    $ rperl -t LearningRPerl/Chapter1/exercise_3-foo_bar_arithmetic.pl 
    have $foo = 33
    have $bar = 966
    have $baz = 29.272_727_272_727_3
    have $zab = 0.034_161_490_683_229_8


Chapter 2, Exercise 1

The goal of this exercise is to become familiar with constant values.
The first line in the CRITICS section tells RPerl to allow hard-coded numeric values as well as the print operator, both of which are utilized in this program.
The second line in the CRITICS section tells RPerl to allow the use constant operation.
The line in the CONSTANTS section declares a number (floating-point) constant value named PI, automatically accessible via a subroutine named PI().
The inner type variable $TYPED_PI is only used for RPerl parsing purposes; for example, if your constant is named FOO then you should declare it using the inner type variable $TYPED_FOO and you should access it by calling the subroutine FOO(), but you should never directly utilize the variable $TYPED_FOO anywhere else in your code.
The first 2 lines in the OPERATIONS section each create a new number variable, with $radius set to the hard-coded value of 12.5 and $circumference set to the well-known basic geometry formula "circumference equals 2 pi times radius".
The last 3 lines call the print operator to display the values of PI, $radius, and $circumference, each followed by a newline character.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 2, Exercise 1
    # Find the circumference of a circle with hard-coded radius of 12.5 units

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitConstantPragma ProhibitMagicNumbers)  # USER DEFAULT 3: allow constants

    # [[[ CONSTANTS ]]]
    use constant PI => my number $TYPED_PI = 3.141_592_654;

    # [[[ OPERATIONS ]]]
    my number $radius = 12.5;
    my number $circumference = 2 * PI() * $radius;

    print 'Pi = ' . to_string(PI()) . "\n";
    print 'Radius = ' . to_string($radius) . "\n";
    print 'Circumference = 2 * Pi * Radius = 2 * ' . to_string(PI()) . ' * ' . to_string($radius) . ' = ' . to_string($circumference) . "\n";

Example execution and output:

    $ rperl -t LearningRPerl/Chapter2/exercise_1-circumference_of_specific_radius.pl 
    Pi = 3._141_592_654
    Radius = 12.5
    Circumference = 2 * Pi * Radius = 2 * 3._141_592_654 * 12.5 = 78.539_816_35


Chapter 2, Exercise 2

The goal of this exercise is to become familiar with accepting user keyboard input.
The third line in the CRITICS section tells RPerl to allow user input via the <STDIN> standard stream, a software input connection which is attached to the keyboard by default.
The second line in the OPERATIONS section creates a string variable $radius_string, and assigns to it the text value typed by the user on their keyboard.
The third line in the OPERATIONS section creates a number variable $radius, and assigns to it the numeric value returned by calling the RPerl type conversion subroutine string_to_number() on the string variable $radius_string.
This exercise is otherwise identical to the previous exercise.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 2, Exercise 2
    # Find the circumference of a circle with any radius entered by the user

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitConstantPragma ProhibitMagicNumbers)  # USER DEFAULT 3: allow constants
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ CONSTANTS ]]]
    use constant PI => my number $TYPED_PI = 3.141_592_654;

    # [[[ OPERATIONS ]]]
    print 'Please input radius: ';
    my string $radius_string = <STDIN>;
    my number $radius = string_to_number($radius_string);
    my number $circumference = 2 * PI() * $radius;

    print "\n";
    print 'Pi = ' . to_string(PI()) . "\n";
    print 'Radius = ' . to_string($radius) . "\n";
    print 'Circumference = 2 * Pi * Radius = 2 * ' . to_string(PI()) . ' * ' . to_string($radius) . ' = ' . to_string($circumference) . "\n";

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter2/exercise_2-circumference_of_any_radius.pl 
    Please input radius: 2

    Pi = 3.141_592_654
    Radius = 2
    Circumference = 2 * Pi * Radius = 2 * 3.141_592_654 * 2 = 12.566_370_616


Chapter 2, Exercise 3

The goal of this exercise is to become familiar with conditional statements and comparison operators.
In the OPERATIONS section, the line starting with if ($radius >= 0) denotes the beginning of a conditional statement: if the numeric value of the variable $radius is greater-than-or-equal-to 0, then the normal calculation for $circumference is used; if $radius is less than 0 (physically impossible), then a warning message is printed and $circumference is set to 0.
This exercise is otherwise identical to the previous exercise.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 2, Exercise 3
    # Find the circumference of a circle with any positive radius entered by the user

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitConstantPragma ProhibitMagicNumbers)  # USER DEFAULT 3: allow constants
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ CONSTANTS ]]]
    use constant PI => my number $TYPED_PI = 3.141_592_654;

    # [[[ OPERATIONS ]]]
    print 'Please input radius: ';
    my string $radius_string = <STDIN>;
    my number $radius = string_to_number($radius_string);
    my number $circumference;

    if ($radius >= 0) {
        $circumference = 2 * PI() * $radius;
    }
    else {
        print 'Negative radius detected, defaulting to zero circumference!' . "\n";
        $circumference = 0;
    }

    print "\n";
    print 'Pi = ' . to_string(PI()) . "\n";
    print 'Radius = ' . to_string($radius) . "\n";
    print 'Circumference = 2 * Pi * Radius = 2 * ' . to_string(PI()) . ' * ' . to_string($radius) . ' = ' . to_string($circumference) . "\n";

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter2/exercise_3-circumference_of_any_positive_radius.pl 
    Please input radius: -2
    Negative radius detected, defaulting to zero circumference!

    Pi = 3._141_592_654
    Radius = -2
    Circumference = 2 * Pi * Radius = 2 * 3._141_592_654 * -2 = 0


Chapter 2, Exercise 4

The goal of this exercise is to gain further exposure to the <STDIN> standard stream and variable multiplication.
In the OPERATIONS section, <STDIN> is accessed to collect user input for both the $multiplicator_string and $multiplicand_string variables.
These 2 string variables are converted from text values to numeric values by calling string_to_number(), then multiplied via the * multiplication operator, and the results displayed by calling print.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 2, Exercise 4
    # Find the product of any two numbers entered by the user

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ OPERATIONS ]]]
    print 'Please input multiplicator: ';
    my string $multiplicator_string = <STDIN>;
    my number $multiplicator = string_to_number($multiplicator_string);

    print 'Please input multiplicand: ';
    my string $multiplicand_string = <STDIN>;
    my number $multiplicand = string_to_number($multiplicand_string);

    my number $product = $multiplicator * $multiplicand;

    print "\n";
    print 'Product = Multiplicator * Multiplicand = ' . to_string($multiplicator) . ' * ' . to_string($multiplicand) . ' = ' . to_string($product) . "\n";

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter2/exercise_4-product_of_any_two_numbers.pl 
    Please input multiplicator: 2112
    Please input multiplicand: 23.42

    Product = Multiplicator * Multiplicand = 2_112 * 23.42 = 49_463.04


Chapter 2, Exercise 5

The goal of this exercise is to become familiar with the x string repeat operator.
In the OPERATIONS section, <STDIN> is accessed twice to collect user input for a string variable $repeat_string to be repeated, and an integer variable $repeat_integer to specify the number of repetitions.
The last line contains 2 operators, print and the x string repeat operator.
Like the . (single dot) string concatenation operator, the x operator has a higher precedence than print and is thus executed first, generating a single string value comprised of the original string repeated 0 or more times, then the resulting string is displayed by calling print.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 2, Exercise 5
    # Repeat any string any number of times, both values entered by the user

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ OPERATIONS ]]]
    print 'Please input string to be repeated: ';
    my string $repeat_string = <STDIN>;

    print 'Please input integer (whole number) times to repeat string: ';
    my string $repeat_integer_string = <STDIN>;
    my integer $repeat_integer = string_to_integer($repeat_integer_string);

    print "\n";
    print $repeat_string x $repeat_integer;

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter2/exercise_5-string_repeat.pl 
    Please input string to be repeated: howdy
    Please input integer (whole number) times to repeat string: 3

    howdy
    howdy
    howdy


Chapter 2, Exercise 6

The goal of this exercise is to become familiar with the while loop control structure.
In the OPERATIONS section, <STDIN> is accessed to collect user input into the string variable $n_string, then the data type conversion subroutine string_to_integer() is called to create the corresponding integer variable $n.
The if ($n < 0) conditional control structure calls die to exit with an error message if $n is not a positive value.
Two additional integer variables are created: $sum is initialized to 0 and will eventually hold the final answer value; and $i is initialized to 0 for use as the iteration counter variable (AKA "iterator") inside the following while loop control structure.
The while loop iteratively executes as long as the integer value of $i is less-than-or-equal-to $n. Each iteration of the while loop causes the value of $sum to be increased by $i, after which $i itself is incremented by 1, and the loop is repeated.
The last line calls print, the to_string() conversion subroutine, and the . (single dot) string concatenation operator to display the final answer.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 2, Exercise 6
    # Calculate the sum of the first n integers; 1 + 2 + 3 + ... + n = ?

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ OPERATIONS ]]]
    print 'Please input a positive integer: ';
    my string $n_string = <STDIN>;
    my integer $n = string_to_integer($n_string);

    if ($n < 0) { die 'ERROR: ' . to_string($n) . ' is not positive, dying' . "\n"; }

    my integer $sum = 0;
    my integer $i = 1;

    while ($i <= $n) {
        $sum += $i;
        $i++;
    }

    print 'The sum of the first ' . to_string($n) . ' integers = ' . to_string($sum) . "\n";

Example executions, input, and output:

    $ rperl -t LearningRPerl/Chapter2/exercise_6-sum_of_first_n_integers.pl 
    Please input a positive integer: 100
    The sum of the first 100 integers = 5_050

    $ rperl -t LearningRPerl/Chapter2/exercise_6-sum_of_first_n_integers.pl 
    Please input a positive integer: -100
    ERROR: -100 is not positive, dying


Chapter 2, Exercise 7

The goal of this exercise is to utilize an optimization to remove the while loop from the previous exercise.
In the OPERATIONS section, user input is collected and error-checked, as before.
By utilizing an algorithm attributed to Gauss, we are able to remove the while loop, so we also remove the $i loop iterator. The $sum variable is kept the same as the previous exercise.
Two new integer variables are also created: $n_original is initialized to hold a copy of $n which will never change; and $n_odd is initialized to 0.
The code block beginning with if ($n % 2) is used to detect if the user provided a value for $n which is odd (not even), this is detected by utilizing the % modulo operator to test for a remainder of dividing $n by 2. If $n is odd, then a second copy of the original value of $n is stored in $n_odd, after which $n itself is decremented by 1. This if statement allows our algorithm to accept odd as well as even user input values for $n.
The computational kernel (most important part) is the one line of arithmetic: $sum = (($n + 1) * ($n / 2)) + $n_odd;
It is said that as a child, Gauss was punished by his teacher by being told to mentally add together all the numbers from 1 to 100. Young Gauss realized that 1 plus 100 is 101, and 2 plus 99 is also 101, as well as 3 plus 98 and so forth. All the numbers may be paired to equal 101, and there are 50 such pairs, so the final answer is 101 multiplied by 50. Thus, with a bit more thought Gauss was able to achieve the answer of 5,050 and perplex his teacher in the process.
Our arithmetic generalizes the idea of young Gauss by using $n instead of 100, and by adding $n_odd to enable support for odd values of $n. Using Gauss' own example of $n equal to 100, which is even (not odd) so $n_odd will equal 0, we can see the algorithm becomes: $sum = ((100 + 1) * (100 / 2)) + 0;
One more step of arithmetic simplification shows our algorithm to be the same as Gauss': $sum = 101 * 50;
The last line calls print using the value of $n_original, because the value of $n will have been decreased by 1 if $n is odd.
It is usually faster to run an algorithm without a loop than with a loop, because you are only doing 1 thing instead of many things. However, not all problems can be easily optimized by changing to a new algorithm, because it may be prohibitively complex or there may only be 1 known algorithm. In this case, Gauss' algorithm should be faster than the while loop algorithm, expecially for very large values of $n. It may be possible to further optimize this exercise by utilizing bitwise operators to replace the modulo and division operators.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 2, Exercise 7
    # Calculate the sum of the first n integers, without using a loop; 1 + 2 + 3 + ... + n = ?

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ OPERATIONS ]]]
    print 'Please input a positive integer: ';
    my string $n_string = <STDIN>;
    my integer $n = string_to_integer($n_string);

    if ($n < 0) { die 'ERROR: ' . to_string($n) . ' is not positive, dying' . "\n"; }

    my integer $sum = 0;
    my integer $n_original = $n;
    my integer $n_odd = 0;

    if ($n % 2) {
        $n_odd = $n;
        $n--;
    }

    $sum = (($n + 1) * ($n / 2)) + $n_odd;

    print 'The sum of the first ' . to_string($n_original) . ' integers = ' . to_string($sum) . "\n";

Example executions, input, and output:

    $ rperl -t LearningRPerl/Chapter2/exercise_7-sum_of_first_n_integers_no_loop.pl 
    Please input a positive integer: 100
    The sum of the first 100 integers = 5_050

    $ rperl -t LearningRPerl/Chapter2/exercise_7-sum_of_first_n_integers_no_loop.pl 
    Please input a positive integer: -100
    ERROR: -100 is not positive, dying


Chapter 3, Exercise 1

The goal of this exercise is to become familiar with the foreach loop control structure, arrays, and array operators; and to become further familiarized with the while loop.
The first line in the OPERATIONS section declares a new variable $input_strings of type string_arrayref, which is capable of storing 0 or more individual string values, and $input_strings is then initialized to contain the empty set [].
The line starting with while (my string $input_string = <STDIN>) denotes the beginning of an iterative (repeating) loop statement, which continues to accept and store user input until CTRL-D is pressed to indicate the EOF (end-of-file) condition, also known as EOT (end-of-transmission).
A new copy of the variable $input_string is created and assigned the value of collected user input by calling <STDIN> at the start of each loop iteration; the my operator is evaluated as a true condition and the loop repeats, until CTRL-D is received and the my operator returns a false condition.
Inside the body of the while loop is 1 line calling the push operator, which appends the current iteration's value of $input_string onto the list of strings contained in $input_strings.
The @{...} (at-sign-curly-braces) is the array dereference operator, which exists because in Perl it is still sometimes necessary to directly access an array by value, instead of the RPerl method of indirectly accessing the array by reference, such as is required by the push operator.
The line starting with my string_arrayref $input_strings_reversed declares another array of string values input_strings_reversed, and then assigns it the strings contained within the first array $input_strings in reversed order, as returned by calling the reverse operator.
As with the push operator, the reverse operator requires its argument to be dereferenced using @{...}; another dereferenced array value is returned by reverse, and an array reference is returned by enclosing reverse and its argument inside the [...] (square brackets) array reference operator.
Finally, the line starting with foreach my string $input_strings_reversed_element denotes the beginning of another loop statement, which iterates the value of $input_strings_reversed_element once for each string value contained in the $input_strings_reversed array; print is called inside the loop body to display the original input strings in reverse order.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 3, Exercise 1
    # Print user-supplied list of strings in reverse order

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ OPERATIONS ]]]
    my string_arrayref $input_strings = [];

    print 'Please input zero or more strings, separated by <ENTER>, ended by <CTRL-D>:' . "\n";

    while (my string $input_string = <STDIN>) {
        push @{$input_strings}, $input_string;
    }

    print "\n";
    print 'Strings in reverse order:' . "\n";

    my string_arrayref $input_strings_reversed = [reverse @{$input_strings}];

    foreach my string $input_strings_reversed_element (@{$input_strings_reversed}) {
        print $input_strings_reversed_element;
    }

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter3/exercise_1-stdin_strings_reverse.pl 
    Please input zero or more strings, separated by <ENTER>, ended by <CTRL-D>:
    howdy
    doody
    buffalo
    bob
    clarabell
    clown

    Strings in reverse order:
    clown
    clarabell
    bob
    buffalo
    doody
    howdy


Chapter 3, Exercise 2

The goal of this exercise is to become familiar with utilizing array indices.
The first line in the OPERATIONS section declares a new variable $flintstones_and_rubbles of type string_arrayref, which is then initialized to contain a qw() (quoted word) set of names including the string element 'fred' at array index 0, 'betty' at array index 1, and so on.
The second line in OPERATIONS creates an empty array of integers $input_indices, and the following while loop uses the push operator to fill $input_indices with integers entered by the user.
The foreach loop iterates through all the user input integers, placing each in the variable $input_index.
Inside the foreach loop, the variable $input_index is used to access the individual names inside the variable $flintstones_and_rubbles.
In Perl, all array indices start at 0 instead of 1, so we must first subtract 1 from $input_index before accessing the individual string elements of $flintstones_and_rubbles.
Thus, if a user inputs the integer 1, the array index will be 0, which is 'fred'; similarly, user input 5 will access array index 4 which is 'wilma'.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 3, Exercise 2
    # Print string array elements indexed by user-supplied integers

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ OPERATIONS ]]]
    my string_arrayref $flintstones_and_rubbles = [qw(fred betty barney dino wilma pebbles bamm-bamm)];
    my integer_arrayref $input_indices          = [];

    print 'Please input zero or more integers with values ranging from 1 to 7, separated by <ENTER>, ended by <CTRL-D>:' . "\n";

    while ( my string $input_string = <STDIN> ) {
        push @{$input_indices}, string_to_integer($input_string);
    }

    print "\n";
    print 'Flintstones & Rubbles:' . "\n";

    foreach my integer $input_index ( @{$input_indices} ) {
        print $flintstones_and_rubbles->[ ( $input_index - 1 ) ] . "\n";
    }

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter3/exercise_2-stdin_array_indices.pl 
    Please input zero or more integers with values ranging from 1 to 7, separated by <ENTER>, ended by <CTRL-D>:
    2
    5
    3
    6
    5
    1
    2
    7
    4
    4

    Flintstones & Rubbles:
    betty
    wilma
    barney
    pebbles
    wilma
    fred
    betty
    bamm-bamm
    dino
    dino


Chapter 3, Exercise 3

The goal of this exercise is to become familiar with the sort and chomp operators.
In the CONSTANTS section, a constant SINGLE_LINE_OUTPUT is created and set to 0, which will cause the program's output to be displayed on multiple lines. If SINGLE_LINE_OUTPUT is instead set to 1, the program's output will be displayed on one line.
In the OPERATIONS section, a while loop is used to fill the array variable $input_strings with data supplied by the user.
The sort operator is then called to fill the $input_strings_sorted array with the same data in ASCII alphabetical order.
Last, a foreach loop is used to print the sorted output by storing and accessing one string at a time in the variable $input_strings_sorted_element.
An if conditional statement inside the foreach loop tests the constant SINGLE_LINE_OUTPUT; if the condition is true, then the chomp operator is called to remove the newline character from each string element and replace it with a normal blank space character, thereby displaying all the elements on a single line of output.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 3, Exercise 3
    # Print user-supplied list of strings in ASCIIbetical order, optionally on single line of output

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitConstantPragma ProhibitMagicNumbers)  # USER DEFAULT 3: allow constants
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ CONSTANTS ]]]
    use constant SINGLE_LINE_OUTPUT => my boolean $TYPED_SINGLE_LINE_OUTPUT = 0;

    # [[[ OPERATIONS ]]]
    my string_arrayref $input_strings = [];

    print 'Please input zero or more strings, separated by <ENTER>, ended by <CTRL-D>:' . "\n";

    while ( my string $input_string = <STDIN> ) {
        push @{$input_strings}, $input_string;
    }

    print "\n";
    print 'Strings in ASCIIbetical order:' . "\n";

    my string_arrayref $input_strings_sorted = [ sort @{$input_strings} ];

    foreach my string $input_strings_sorted_element ( @{$input_strings_sorted} ) {
        if ( SINGLE_LINE_OUTPUT() ) {

            # strip trailing newline, if present
            chomp $input_strings_sorted_element;
            $input_strings_sorted_element .= q{ };
        }

        print $input_strings_sorted_element;
    }

    print "\n";

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter3/exercise_3-stdin_strings_sort.pl 
    Please input zero or more strings, separated by <ENTER>, ended by <CTRL-D>:
    howdy
    doody
    buffalo
    bob
    clarabell
    clown

    Strings in ASCIIbetical order:
    bob
    buffalo
    clarabell
    clown
    doody
    howdy


Chapter 4, Exercise 1

The goal of this exercise is to become familiar with user-defined subroutines.
In the SUBROUTINES section, one subroutine total() is defined, which accepts as input one argument variable $input_numbers of type number_arrayref, and which also has a number return value stored in the variable $retval.
Inside the total() subroutine, the return value is initialized to 0 in $retval, then a foreach loop iteratively adds the elements of the array $input_numbers to $retval, after which the value of $retval is returned to original external caller of total().
By itself, a subroutine such as total() does not actually do anything; every subroutine must first be called either by some other subroutine or in the OPERATIONS section.
In OPERATIONS, a 5-element array is created and stored in the variable $fred, which is then passed as input to the subroutine total(), and the return value is displayed using the variable $fred_total and the print operator.
Next, a while loop and <STDIN> are used to collect user input strings, which are then converted to numeric data values using the string_to_number() subroutine, and stored in the array $input_numbers using the push operator.
Finally, the subroutine total() is called a second time, now with the variable $input_numbers passed as the input argument, and the return value is displayed using the variable $user_total.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 4, Exercise 1
    # Subroutine & driver to calculate the totals of arrays of stringified numbers, both hard-coded and user-supplied

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(RequireInterpolationOfMetachars)  # USER DEFAULT 2: allow single-quoted control characters & sigils
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ SUBROUTINES ]]]

    our number $total = sub {
        (my number_arrayref $input_numbers) = @_;
        my number $retval = 0;
        foreach my number $input_number (@{$input_numbers}) {
            $retval += $input_number;
        }
        return $retval;
    };

    # [[[ OPERATIONS ]]]

    my number_arrayref $fred = [1, 3, 5, 7, 9];
    my number $fred_total = total($fred);
    print 'The total of $fred is ' . to_string($fred_total) . "\n";

    print 'Please input zero or more numbers, separated by <ENTER>, ended by <CTRL-D>:' . "\n";

    my number_arrayref $input_numbers = [];
    while (my string $input_string = <STDIN>) {
        push @{$input_numbers}, string_to_number($input_string);
    }

    my number $user_total = total($input_numbers);
    print 'The total of those numbers is ' . to_string($user_total) . "\n";

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter4/exercise_1-subroutine_total.pl 
    The total of $fred is 25
    Please input zero or more numbers, separated by <ENTER>, ended by <CTRL-D>:
    21.12
    23.42
    1701.877
    -123.456
    The total of those numbers is 1_622.961


Chapter 4, Exercise 2

The goal of this exercise is to become familiar with the .. range operator.
In the SUBROUTINES section, the same subroutine total() is defined as in the previous exercise.
In the OPERATIONS section, an array of numbers is created and stored in the variable $one_to_one_thousand.
Upon execution, there will be 1,000 number elements in the array, which are automatically created by the .. range operator.
The actual elements stored the array variable $one_to_one_thousand start with [1, 2, 3, 4 and end with 997, 998, 999, 1_000].
Finally, the subroutine total() is called with $one_to_one_thousand passed as the input argument, and the return value is displayed using the variable $one_to_one_thousand_total.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 4, Exercise 2
    # Subroutine & driver to calculate the total of 1 to 1,000

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator

    # [[[ SUBROUTINES ]]]

    our number $total = sub {
        ( my number_arrayref $input_numbers ) = @_;
        my number $retval = 0;
        foreach my number $input_number ( @{$input_numbers} ) {
            $retval += $input_number;
        }
        return $retval;
    };

    # [[[ OPERATIONS ]]]

    my number_arrayref $one_to_one_thousand = [ 1 .. 1_000 ];
    my number $one_to_one_thousand_total    = total($one_to_one_thousand);
    print 'The total of 1 to 1_000 is ' . to_string($one_to_one_thousand_total) . q{.} . "\n";

Example execution and output:

    $ rperl -t LearningRPerl/Chapter4/exercise_2-subroutine_total_1000.pl 
    The total of 1 to 1000 is 500_500.


Chapter 4, Exercise 3

The goal of this exercise is to become familiar with calling user-defined subroutines from one another.
In the SUBROUTINES section, 3 subroutines are defined: total() (same as previous exercises), average(), and above_average().
Inside the subroutine average() is a call to the subroutine total(); there is also a call to the scalar operator, which returns the count of elements inside the array $input_numbers. When the return value of total() is divided by that of scalar, the result is computation of the numeric mean (average) of all elements of $input_numbers.
Inside above_average() is a call to the subroutine average(), with the return value stored in the variable $average. An empty array is created in the variable $retval, then a foreach loop iterates over all elements in $input_numbers and an if conditional statement makes a copy of all elements which are greater than $average. All above-average elements are returned as an array in $retval.
In the OPERATIONS section, 2 arrays are created in the $fred and $barney variables, which are then passed as input arguments to 2 calls to the subroutine above_average(), and the results are displayed.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 4, Exercise 3
    # Subroutines & driver to calculate the above-average elements of hard-coded arrays

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(RequireInterpolationOfMetachars)  # USER DEFAULT 2: allow single-quoted control characters & sigils
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ SUBROUTINES ]]]

    our number $total = sub {
        ( my number_arrayref $input_numbers ) = @_;
        my number $retval = 0;
        foreach my number $input_number ( @{$input_numbers} ) {
            $retval += $input_number;
        }
        return $retval;
    };  

    our number $average = sub {
        ( my number_arrayref $input_numbers ) = @_;
        return (total($input_numbers) / (scalar @{$input_numbers}));
    };

    our number_arrayref $above_average = sub {
        ( my number_arrayref $input_numbers ) = @_;
        my number $average = average($input_numbers);
        my number_arrayref $retval = [];
        foreach my number $input_number (@{$input_numbers}) {
            if ($input_number > $average) {
                push @{$retval}, $input_number;
            }
        }
        return $retval;
    };

    # [[[ OPERATIONS ]]]

    my string_arrayref $fred = [1 .. 10];
    my number $fred_above_average = above_average($fred);
    print '$fred is ' . number_arrayref_to_string($fred) . "\n";
    print 'The above-average elements of $fred are ' . number_arrayref_to_string($fred_above_average) . "\n";
    print '(Should be [6, 7, 8, 9, 10])' . "\n\n";

    my string_arrayref $barney = [100, 1 .. 10];
    my number $barney_above_average = above_average($barney);
    print '$barney is ' . number_arrayref_to_string($barney) . "\n";
    print 'The above-average elements of $barney are ' . number_arrayref_to_string($barney_above_average) . "\n";
    print '(Should be just [100])' . "\n";

Example execution and output:

    $ rperl -t LearningRPerl/Chapter4/exercise_3-subroutine_above_average.pl 
    $fred is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    The above-average elements of $fred are [6, 7, 8, 9, 10]
    (Should be [6, 7, 8, 9, 10])

    $barney is [100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    The above-average elements of $barney are [100]
    (Should be just [100])


Chapter 4, Exercise 4

The goal of this exercise is to become familiar with program state.
As a program executes, there may be one or more variables in the OPERATIONS section which store information that is important to the overall program; these variables are collectively known as the "state" of the program.
In the OPERATIONS section, a string variable $previous_name is created and set to the empty string q{}; this 1 variable is the state of the program.
Each of the 4 following lines in the OPERATIONS section utilize the program state by both reading from and writing to the variable $previous_name; the calls to the subroutine greet() read from $previous_name as the 2nd argument, and the return value of greet() is then written to $previous_name by the = assignment operator.
In the SUBROUTINES section, 1 subroutine greet() is defined which accepts 2 string arguments, the variables $name and $previous_name.
Inside greet(), a personalized greeting is displayed for the virtual person represented by the variable $name, after which an if() else conditional statement checks if there is any data inside $previous_name and further displays a customized comment about the state of the program. The state variable $previous_name is used to represent the very simple state of virtual people who have already been greeted.
Finally, the string variable $name is returned from greet() and passed to the = assignment operators in the OPERATIONS section, thereby updating the program state variable $previous_name to contain the value of $name.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 4, Exercise 4
    # Subroutine & driver to greet users

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator

    # [[[ SUBROUTINES ]]]

    our string $greet = sub {
        ( my string $name, my string $previous_name ) = @_;
        print 'Hi ' . $name . '!  ';
        if ($previous_name eq q{}) {
            print 'You are the first one here!' . "\n";
        }
        else {
            print $previous_name . ' is also here!' . "\n";
        }
        return $name;
    };

    # [[[ OPERATIONS ]]]

    my string $previous_name = q{};
    $previous_name = greet('Fred', $previous_name);
    $previous_name = greet('Barney', $previous_name);
    $previous_name = greet('Wilma', $previous_name);
    $previous_name = greet('Betty', $previous_name);

Example execution and output:

    $ rperl -t LearningRPerl/Chapter4/exercise_4-subroutine_greet.pl 
    Hi Fred!  You are the first one here!
    Hi Barney!  Fred is also here!
    Hi Wilma!  Barney is also here!
    Hi Betty!  Wilma is also here!


Chapter 4, Exercise 5

The goal of this exercise is to become further familiarized with program state.
In the OPERATIONS section, the state variable $previous_names is an array of strings representing all previous virtual people who have been greeted.
In the SUBROUTINES section, the subroutine greet() prints the names of previously-greeted virtual people on one line, separated by spaces, by using the join operator.
Finally, the current value of $name is appended as the last element of the array $previous_names by the push operator, and $previous_names is then returned by greet() to update the program state.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 4, Exercise 5
    # Subroutine & driver to greet multiple users

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator

    # [[[ SUBROUTINES ]]]

    our string_arrayref $greet = sub {
        ( my string $name, my string_arrayref $previous_names ) = @_;
        print 'Hi ' . $name . '!  ';
        if ((scalar @{$previous_names}) == 0) {
            print 'You are the first one here!' . "\n";
        }
        else {
            print q{I've seen: } . (join q{ }, @{$previous_names}) . "\n";
        }
        push @{$previous_names}, $name;
        return $previous_names;
    };

    # [[[ OPERATIONS ]]]

    my string_arrayref $previous_names = [];
    $previous_names = greet('Fred', $previous_names);
    $previous_names = greet('Barney', $previous_names);
    $previous_names = greet('Wilma', $previous_names);
    $previous_names = greet('Betty', $previous_names);

Example execution and output:

    $ rperl -t LearningRPerl/Chapter4/exercise_5-subroutine_greet_multiple.pl 
    Hi Fred!  You are the first one here!
    Hi Barney!  I've seen: Fred
    Hi Wilma!  I've seen: Fred Barney
    Hi Betty!  I've seen: Fred Barney Wilma


Chapter 5, Exercise 1

The goal of this exercise is to become familiar with file test operators, as well as opening, closing, and reading from a file.
In the CRITICS section, the ProhibitPostfixControls critic is disabled due to a bug in Perl::Critic and/or PPI which causes a false error.
In the SUBROUTINES section, 1 subroutine tac() is defined which accepts as input an array of file names received via the operating system's command-line arguments, and which has a void return value, meaning there is no return value for this subroutine.
Inside tac(), the reverse operator is called to reverse the order of the command-line arguments; for example, if the 3 file names fred barney betty are given as command-line arguments, then reverse causes the 3 strings betty barney fred to be stored in the array variable $command_line_arguments.
The outer foreach loop iterates through each $file_name in the now-reversed $command_line_arguments.
Next, 4 file test operators are called, to ensure each input file exists via -e, is readable via -r, is a regular (not special device) file via -f, and is comprised of plain text via -T.
The operator open is called with the < file input (read-only) argument, which opens each $file_name for reading via the $FILE filehandle variable.
The inner while loop reads in all lines from the current $FILE filehandle using the <$FILE> syntax (similar to <STDIN>) and stores the input file's lines in the string array variable $file_lines; then, the reverse operator is called again to reverse the order of the newly-read file lines.
Finally, the inner foreach loop displays the now-reversed $file_lines, and the close operator is called to close the $FILE filehandle so no more file access will occur for the current $file_name.
In the OPERATIONS section, the tac() subroutine is called with its only argument being a reference to the special @ARGV array, which is Perl's way of accessing the command-line arguments.
Before executing this program, the non-Perl printf program must be called to populate some test data into the 3 input files fred, barney, and betty; and after execution the rm program is called to delete the 3 input files.
To begin execution of this program via the rperl command, the program name and input file names must be enclosed in either 'single quotes' or "double quotes"; this tells RPerl the input file names are command-line arguments to be passed to the 1 specified program, instead of specifying additional RPerl programs.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 5, Exercise 1
    # Accept one or more input files, and print their contents line-by-line in reverse order

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitPostfixControls)  # SYSTEM SPECIAL 6: PERL CRITIC FILED ISSUE #639, not postfix foreach or if

    # [[[ SUBROUTINES ]]]

    our void $tac = sub {
        ( my string_arrayref $command_line_arguments ) = @_;
        $command_line_arguments = [ reverse @{$command_line_arguments} ];
        foreach my string $file_name ( @{$command_line_arguments} ) {
            if ( not( -e $file_name ) ) {
                croak 'ERROR: File ' . $file_name . ' does not exist, croaking';
            }
            if ( not( -r $file_name ) ) {
                croak 'ERROR: File ' . $file_name . ' is not readable, croaking';
            }
            if ( not( -f $file_name ) ) {
                croak 'ERROR: File ' . $file_name . ' is not a regular file, croaking';
            }
            if ( not( -T $file_name ) ) {
                croak 'ERROR: File ' . $file_name . ' is (probably) not text, croaking';
            }

            my integer $open_success = open my filehandleref $FILE, '<', $file_name;
            if ( not $open_success ) {
                croak 'ERROR: Failed to open file ' . $file_name . ' for reading, croaking';
            }

            my string_arrayref $file_lines = [];

            while ( my string $file_line = <$FILE> ) {
                push @{$file_lines}, $file_line;
            }

            $file_lines = [ reverse @{$file_lines} ];

            foreach my string $file_line ( @{$file_lines} ) {
                print $file_line;
            }

            if ( not close $FILE ) {
                croak 'ERROR: Failed to close file ' . $file_name . ' after reading, croaking';
            }
        }
    };

    # [[[ OPERATIONS ]]]

    tac( [@ARGV] );

Example execution, input, and output:

    $ printf "fred0\nfred1\nfred2\nfred3\nfred4\n" > fred
    $ printf "barney0\nbarney1\nbarney2\n" > barney
    $ printf "betty0\nbetty1\nbetty2\nbetty3\n" > betty
    $ rperl -t 'LearningRPerl/Chapter5/exercise_1-tac.pl fred barney betty'
    betty3
    betty2
    betty1
    betty0
    barney2
    barney1
    barney0
    fred4
    fred3
    fred2
    fred1
    fred0
    $ rm fred barney betty


Chapter 5, Exercise 2

The goal of this exercise is to become familiar with the string length operator and basic text formatting.
In the SUBROUTINES section, 1 subroutine right_justify_20() is defined, which accepts no input arguments and returns no values.
Inside right_justify_20(), an empty array of strings is initialized in the $input_strings variable, which is then populated with strings in a while loop collecting user input from <STDIN>.
The x string repeat operator is called to create a 60-character-wide horizontal ruler, which is then displayed by the print operator.
Finally, a foreach loop iterates through each $input_string and calls the length operator, thereby determining the correct number of spaces to prepend in order to achieve right justification alignment to the 20th character column. The - subtraction operator is passed a hard-coded column width of 20, and the chomp operator is called to remove any trailing newline characters which may be appended when the user presses the ENTER key after each input word.
In the OPERATIONS section, the only operation is a call to the right_justify_20() subroutine.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 5, Exercise 2
    # Accept one or more input lines, and print them in a right-justified 20-column format

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ SUBROUTINES ]]]

    our void $right_justify_20 = sub {
        my string_arrayref $input_strings = [];
        print 'Please input zero or more strings, separated by <ENTER>, ended by <CTRL-D>:' . "\n";
        while ( my string $input_string = <STDIN> ) {
            push @{$input_strings}, $input_string;
        }

        print "\n";
        print '1234567890' x 6;
        print "\n";

        foreach my string $input_string ( @{$input_strings} ) {
            chomp $input_string;
            print q{ } x ( 20 - ( length $input_string ) );
            print $input_string . "\n";
        }
    };

    # [[[ OPERATIONS ]]]

    right_justify_20();

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter5/exercise_2-right_justify.pl
    Please input zero or more strings, separated by <ENTER>, ended by <CTRL-D>:
    howdy
    doody
    buffalo
    bob
    clarabell
    clown

    123456789012345678901234567890123456789012345678901234567890
                   howdy
                   doody
                 buffalo
                     bob
               clarabell
                   clown


Chapter 5, Exercise 3

The goal of this exercise is to become further familiarized with basic text formatting.
In the SUBROUTINES section, 1 subroutine right_justify_variable() is defined, which accepts no input arguments and returns no values.
Inside right_justify_variable(), the user is prompted to input a custom right justify width, stored in the integer variable $column_width.
The integer variable $ruler_width_tens is used to determine the number of characters displayed for the ruler, by tens; the default value for $ruler_width_tens is 6, which means a ruler width of 60 characters. If the user-supplied $column_width is greater than 60, we scale it by 1/10 and add 1, thereby creating a new value for $ruler_width_tens which will always display a ruler wider than $column_width.
When the ruler is displayed, $ruler_width_tens is passed to the x string repeat operator instead of a hard-coded value of 6; likewise, when each $input_string is right justified, the - subtraction operator is passed $column_width instead of a hard-coded value of 20.
In the OPERATIONS section, the only operation is a call to the right_justify_variable() subroutine.
This exercise is otherwise identical to the previous exercise.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 5, Exercise 3
    # Accept column width followed by one or more input lines, and print lines in a right-justified format

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ SUBROUTINES ]]]

    our void $right_justify_variable = sub {
        my string_arrayref $input_strings = [];
        print 'Please input integer column width, then press <ENTER>:' . "\n";
        my string $column_width_string = <STDIN>;
        my integer $column_width       = string_to_integer($column_width_string);

        print 'Please input zero or more strings, separated by <ENTER>, ended by <CTRL-D>:' . "\n";
        while ( my string $input_string = <STDIN> ) {
            push @{$input_strings}, $input_string;
        }

        my integer $ruler_width_tens = 6;    # default to ruler line width 60
        if ( $column_width > 60 ) {
            $ruler_width_tens = number_to_integer( $column_width / 10 ) + 1;
        }

        print "\n";
        print '1234567890' x $ruler_width_tens;
        print "\n";

        foreach my string $input_string ( @{$input_strings} ) {
            chomp $input_string;
            print q{ } x ( $column_width - ( length $input_string ) );
            print $input_string . "\n";
        }
    };

    # [[[ OPERATIONS ]]]

    right_justify_variable();

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter5/exercise_3-right_justify_variable.pl 
    Please input integer column width, then press <ENTER>:
    67
    Please input zero or more strings, separated by <ENTER>, ended by <CTRL-D>:
    howdy
    doody
    buffalo
    bob
    clarabell
    clown

    1234567890123456789012345678901234567890123456789012345678901234567890
                                                                  howdy
                                                                  doody
                                                                buffalo
                                                                    bob
                                                              clarabell
                                                                  clown


Chapter 6, Exercise 1

The goal of this exercise is to become familiar with hash data structures and hash operators.
In the SUBROUTINES section, 1 subroutine given_to_family_name() is defined, which accepts no input arguments and returns no values.
Inside given_to_family_name(), a hash data structure is created in the variable $names. Another term for hash is associative array, because each hash is comprised of key-value pairs, and we say there is a value "associated" with every key. Hash keys are bare words and must be unique, while hash values may be any specified data type and need not be unique. The 3 keys in $names are fred, barney, and wilma; the value of the key fred is 'flintstone'.
A first name is collected from the user by <STDIN> and stored in $given_name, then the chomp operator is called to remove the trailing newline recorded when the user presses the ENTER key.
An if conditional statement calls the exists and defined operators to ensure the user has entered a valid hash key, and an error is returned if there is no such key in the $names hash.
Finally, the thin-arrow syntax $names->{$given_name} is used to retrieve the hash value, and print is called to display the family name outputs.
In the OPERATIONS section, the only operation is a call to the given_to_family_name() subroutine.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 6, Exercise 1
    # Accept one input given (first) name, and print the corresponding family (last) name

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ SUBROUTINES ]]]

    our void $given_to_family_name = sub {
        my string_hashref $names = {
            fred => 'flintstone',
            barney => 'rubble',
            wilma => 'flintstone'
        };

        print 'Please input a given (first) name in all lowercase, then press <ENTER>:' . "\n";
        my string $given_name = <STDIN>;
        chomp $given_name;

        if ((not exists $names->{$given_name}) or (not defined $names->{$given_name})) {
            croak 'ERROR: No family (last) name found for given (first) name ' . $given_name . ', croaking' . "\n";
        }

        print 'The family (last) name of ' . $given_name . ' is ' . $names->{$given_name} . q{.} . "\n";
    };

    # [[[ OPERATIONS ]]]

    given_to_family_name();

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter6/exercise_1-hash_family_names.pl 
    Please input a given (first) name in all lowercase, then press <ENTER>:
    fred
    The family (last) name of fred is flintstone.

    $ rperl -t LearningRPerl/Chapter6/exercise_1-hash_family_names.pl 
    Please input a given (first) name in all lowercase, then press <ENTER>:
    howdy
    ERROR: No family (last) name found for given (first) name howdy, croaking


Chapter 6, Exercise 2

The goal of this exercise is to become further familiarized with hash data structures and hash operators.
In the SUBROUTINES section, 1 subroutine unique_word_count() is defined, which accepts no input arguments and returns no values.
In unique_word_count(), an empty hash of integer values is created in the variable $word_counts; a while loop then collects user input strings, inside of which an if() else conditional statement updates the $word_counts hash. If a word is seen for the first time, then the corresponding $word_counts hash value will be set to 1, otherwise the count value will be incremented by 1.
Finally, a foreach loop iterates through the alphabetically-sorted keys of the $word_counts hash by calling the sort and keys operators, then the thin-arrow hash value retrieval syntax $word_counts->{$unique_word} is called, and the print operator displays the word count outputs.
In the OPERATIONS section, the only operation is a call to the unique_word_count() subroutine.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 6, Exercise 2
    # Accept a list of words, and print the count of each unique word

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
    ## no critic qw(ProhibitExplicitStdin)  # USER DEFAULT 4: allow <STDIN> prompt

    # [[[ SUBROUTINES ]]]

    our void $unique_word_count = sub {
        my integer_hashref $word_counts = {};

        print 'Please input zero or more words, separated by <ENTER>, ended by <CTRL-D>:' . "\n";
        while (my string $input_word = <STDIN>) {
            chomp $input_word;
            if (not exists $word_counts->{$input_word}) {
                $word_counts->{$input_word} = 1;
            }
            else {
                $word_counts->{$input_word} += 1;
            }
        }

        print "\n" . 'Unique word count:' . "\n";

        foreach my string $unique_word (sort keys %{$word_counts}) {
            print $unique_word . ' appeared ' . to_string($word_counts->{$unique_word}) . ' time(s)' . "\n";
        }
    };

    # [[[ OPERATIONS ]]]

    unique_word_count();

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter6/exercise_2-hash_unique_word_count.pl 
    Please input zero or more words, separated by <ENTER>, ended by <CTRL-D>:
    george
    jane
    judy
    elroy
    astro
    rosie
    george
    judy
    astro
    fred
    wilma
    barney
    betty
    pebbles
    bamm-bamm
    dino
    fred
    barney
    dino
    george
    fred
    barney
    astro
    dino
    jane
    judy
    betty
    wilma

    Unique word count:
    astro appeared 3 time(s)
    bamm-bamm appeared 1 time(s)
    barney appeared 3 time(s)
    betty appeared 2 time(s)
    dino appeared 3 time(s)
    elroy appeared 1 time(s)
    fred appeared 3 time(s)
    george appeared 3 time(s)
    jane appeared 2 time(s)
    judy appeared 3 time(s)
    pebbles appeared 1 time(s)
    rosie appeared 1 time(s)
    wilma appeared 2 time(s)


Chapter 6, Exercise 3

The goal of this exercise is to become further familiarized with hash data structures and basic text formatting.
In the SUBROUTINES section, 1 subroutine sort_env_vars() is defined, which accepts no input arguments and returns no values.
Inside sort_env_vars(), a hash of strings is created in the variable $env_vars, and it is initialized to contain the values of the special %ENV system hash, which stores the current user's environmental variables.
Next, 2 integer variables $env_var_length and $left_column_width are created, and $left_column_width is initialized to the value 0. A foreach loop iterates through all environmental variables, measuring the string length of each $env_var by the length operator, and using an if conditional statement to test if the current $env_var_length is greater than the existing $left_column_width. If $env_var_length is large enough, then $left_column_width is updated, thereby resulting in the value of $left_column_width being equal to the longest $env_var_length.
After the foreach loop, $left_column_width is incremented by an additional 2 character widths, allowing for 2 or more spaces between the hash keys and their respective values when displayed.
Finally, there is another foreach loop below the first, again iterating through all $env_vars, and printing the keys at the beginning of each output line. The - subtraction operator is called to find the difference between the current key length and the pre-calculated $left_column_width, then the x string repeat operator is called to create the corresponding number of blank spaces as padding between the key and its value. The thin-arrow hash value retrieval syntax $env_vars->{$env_var} is called, and the print operator displays the hash value outputs.
In the OPERATIONS section, the only operation is a call to the sort_env_vars() subroutine.

    #!/usr/bin/perl

    # Learning RPerl, Chapter 6, Exercise 3
    # Print sorted environmental variables

    # [[[ HEADER ]]]
    use RPerl;
    use strict;
    use warnings;
    our $VERSION = 0.001_000;

    # [[[ CRITICS ]]]
    ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator

    # [[[ SUBROUTINES ]]]

    our void $sort_env_vars = sub {
        my string_hashref $env_vars = {%ENV};

        my integer $env_var_length;
        my integer $left_column_width = 0;
        foreach my string $env_var ( sort keys %{$env_vars} ) {
            $env_var_length = length $env_var;
            if ( $env_var_length > $left_column_width ) {
                $left_column_width = $env_var_length;
            }
        }

        $left_column_width += 2;

        print 'Environmental variables:' . "\n";

        foreach my string $env_var ( sort keys %{$env_vars} ) {
            print $env_var;
            print q{ } x ( $left_column_width - ( length $env_var ) );
            print $env_vars->{$env_var} . "\n";
        }
    };

    # [[[ OPERATIONS ]]]

    sort_env_vars();

Example execution, input, and output:

    $ rperl -t LearningRPerl/Chapter6/exercise_3-hash_sort_env_vars.pl 
    Environmental variables:
    COLORTERM                 xfce4-terminal
    DESKTOP_SESSION           xubuntu
    DISPLAY                   :0.0
    GDMSESSION                xubuntu
    GDM_LANG                  en_US
    HOME                      /home/wbraswell
    LANG                      en_US.UTF-8
    LANGUAGE                  en_US
    LOGNAME                   wbraswell
    PATH                      /home/wbraswell/austin_perl_mongers/rperl/rperl-latest/script:.:script:bin:/home/wbraswell/script:/home/wbraswell/bin:/home/wbraswell/perl5/bin:/home/wbraswell/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    PERL5LIB                  /home/wbraswell/austin_perl_mongers/rperl/rperl-latest/lib:blib/lib:lib:/home/wbraswell/perl5/lib/perl5
    PERL_LOCAL_LIB_ROOT       /home/wbraswell/perl5
    PERL_MB_OPT               --install_base "/home/wbraswell/perl5"
    PERL_MM_OPT               INSTALL_BASE=/home/wbraswell/perl5
    PWD                       /home/wbraswell/austin_perl_mongers/rperl/rperl-latest
    SHELL                     /bin/bash
    TERM                      xterm
    USER                      wbraswell


APPENDIX B: RPERL GRAMMAR

B.1: Eyapp Grammar Format & Sections

RPerl's grammar is written using the Eyapp computer programming language, which is a combination of normal Perl 5 and grammar expressions.

The grammar expression sections in Eyapp source code are written using an implementation of the Extended Backus-Naur Form (EBNF) language.

The file lib/RPerl/Grammar.eyp contains the uncompiled RPerl grammar, which is passed through the eyapp compiler command once to generate the output file lib/RPerl/Grammar.pm, which is then used by the rperl compiler command to parse RPerl input source code files.

Inside the lib/RPerl/Grammar.eyp file, there are several labeled file sections, which can be grouped into 4 major categories:

For more information, please view the following links:

B.2: Lexicon Token Types

Following is a list of all RPerl tokens in all 4 lexicon sections, along with examples of valid matching lexeme input.

The list must be in correct order for all regexes to match; earlier declarations get tried first, thus highly-specific tokens such as RPerl keywords and built-in operators appear first, while the least-specific tokens such as user-defined words appear last. This ordering can be considered "lexical matching", and is distinct from operator precedence and associativity as covered in the next section.

B.2.1: Whitespace

[[[ LEXICON TOKENS, WHITESPACE ]]]

B.2.2: Types & Reserved Words

[[[ LEXICON TOKENS, TYPES & RESERVED WORDS ]]]

B.2.3: Operators

[[[ LEXICON TOKENS, OPERATORS ]]]

B.2.4: Punctuation & User-Defined Words

[[[ LEXICON TOKENS, PUNCTUATION & USER-DEFINED WORDS ]]]

B.3: Syntax Arity, Fixity, Precedence, Associativity

Operator "arity" is a technical term which means the number of input operands accepted by a specific built-in operator, or the number of input arguments accepted by a user-defined function. An operator or function which accepts 0 input arguments is known as "nullary", 1 argument as "unary", 2 arguments as "binary", 3 arguments as "ternary", and so forth. The exit; operator may be called as nullary; the ++ increment operator is unary; the + addition operator is binary; and the substr operator may be called as ternary. Not to be confused with "a ternary operator", meaning any operator which accepts 3 operands, there is one specific operator known as "the ternary operator", which is a special kind of conditional operator accepting 3 input arguments. An operator or function which may accept more than one number of arguments is known as "variadic". Some RPerl operators are variadic, such as substr which may accept 2, 3, or 4 arguments. RPerl does not currently support variadic user-defined functions.

Operator Arity on Wikipedia

Operator "fixity" is the notation form indicating the location of an operator when placed relative to its own input operands. "Prefix" operators are located before their operands, "infix" between operands, and "postfix" after operands. Additionally, operators which must be placed both before and after their operands are said to be of "closed" fixity, while operators capable of more than one placement location are called "mixfix". Prefix notation is also known as "Polish notation", and postfix is called "Reverse Polish" notation. The abs absolute value is a prefix operator; the + addition operator is infix; and the ++ increment operator can be called as postfix. The -( ) negative-with-parentheses operator is of closed fixity, because the parentheses component must appear both before and after the enclosed operand. Parentheses are always of closed fixity; in normal Perl, the - negative (without parentheses) is a prefix operator, but in RPerl we only allow the closed fixity -( ) negative-with-parentheses operator in order to avoid grammar ambiguity, because the same - dash (AKA hyphen) character is utilized for both the - negative and - subtraction operators. The ++ increment operator may also be called as prefix, so it may be classified as mixfix.

Prefix Notation on Wikipedia

Infix Notation on Wikipedia

Postfix Notation on Wikipedia

Operator "precedence", also known as "order-of-operations", is a methodology used to determine which operator is executed first when 2 or more operators are adjacent to one another and parentheses are not used to explicitly separate them. A numeric precedence from 1 to 24 is assigned to each operator, and the operator with the lowest precedence number is given priority to execute first. Low precedence number equals high priority. The * arithmetic multiplication operator has a precedence number of 7, and + addition has a precedence of 8, so a + b * c is equivalent to a + (b * c), not (a + b) * c.

Operator Precedence on Wikipedia

Operator "associativity" is used to further determine precedence when multiple operators of the same priority are adjacent to one another. Each operator is designated as left-associative, right-associative, or non-associative. (Wikipedia incorrectly identifies associativity as a synonym for fixity, which is different, as described above.) Normal arithmetic operators are left-associative, meaning a - b - c is equivalent to (a - b) - c, not a - (b - c). Some operators such as mathematic power (AKA exponentiation) are right-associative, meaning a ** b ** c is equivalent to a ** (b ** c). Operators which are not meant to be chained together are non-associative, such as the .. list range operator which takes scalar values as input but generates an array as output, so a .. b .. c is incorrect usage and will cause an error.

Operator Associativity on Wikipedia

In the following list of operators copied directly from Grammar.eyp, later declaration gets higher priority, so all precedence numbers appear in strictly descending order from 24 to 1. (Implementation of operator arity and fixity are a bit less straightforward, and are not easily copied-and-pasted in one succinct list directly out of Grammar.eyp.) All operator arity, fixity, precedence, and associativity are taken directly from Perl 5.

Operator Precedence & Associativity in Perl 5 Documentation [1]

[[[ SYNTAX, OPERATOR PRECEDENCE & ASSOCIATIVITY ]]]

    %left       OP24_LOGICAL_OR_XOR
    %left       OP23_LOGICAL_AND
    %right      OP22_LOGICAL_NEG
    %left       OP21_LIST_COMMA
    %left       OP20_HASH_FATARROW
    %right      OP19_LOOP_CONTROL_SCOLON
    %right      OP19_LOOP_CONTROL
    %right      OP19_VARIABLE_ASSIGN_BY
    %right      OP19_VARIABLE_ASSIGN
    %right      OP18_TERNARY
    %nonassoc   OP17_LIST_RANGE
    %left       OP16_LOGICAL_OR
    %left       OP15_LOGICAL_AND
    %left       OP14_BITWISE_OR_XOR
    %left       OP13_BITWISE_AND
    %nonassoc   OP12_COMPARE_EQ_NE
    %nonassoc   OP11_COMPARE_LT_GT
    %nonassoc   OP10_NAMED_UNARY
    %nonassoc   OP10_NAMED_UNARY_SCOLON
    %left       OP09_BITWISE_SHIFT
    %left       OP08_STRING_CAT
    %left       OP08_MATH_ADD_SUB
    %left       OP07_MATH_MULT_DIV_MOD
    %left       OP07_STRING_REPEAT
    %left       OP06_REGEX_MATCH
    %left       OP06_REGEX_PATTERN
    %right      OP05_MATH_NEG_LPAREN
    %right      OP05_LOGICAL_NEG
    %right      OP04_MATH_POW
    %nonassoc   OP03_MATH_INC_DEC
    %left       OP02_HASH_THINARROW
    %left       OP02_ARRAY_THINARROW
    %left       OP02_METHOD_THINARROW_NEW
    %left       OP02_METHOD_THINARROW
    %left       OP01_NAMED
    %left       OP01_NAMED_SCOLON
    %left       OP01_CLOSE
    %left       OP01_OPEN
    %left       OP01_QW
    %left       OP01_NAMED_VOID_SCOLON
    %left       OP01_NAMED_VOID_LPAREN
    %left       OP01_NAMED_VOID
    %left       OP01_PRINT

B.4: Syntax Production Rules

The EBNF metasyntax implemented by Eyapp is of the form:

ProductionRule: First Alternative 'foo' | Second Alternative 'bar' | ... | Last Alternative 'quux' ;

In this example, ProductionRule is a non-terminal left-hand-side (LHS) symbol, is followed by the : reduction metasymbol, and may be reduced (replaced) by any of the right-hand-side (RHS) sequences of terminal and non-terminal symbols, themselves separated by the | alternation (logical or) metasymbol. In other words, each LHS may become any of its corresponding RHS alternatives.

Terminal symbols are enclosed in single quotes as with 'foo', never appear on the LHS, and are taken as literal data with no transformations applied. Eyapp treats terminal symbols as tokens which only match one hard-coded lexeme, which is the string appearing inside the single quotes, foo in this example.

B.4.1: File Formats

[[[ SYNTAX PRODUCTION RULES, FILE FORMATS ]]]

    CompileUnit:             Program | (ModuleHeader Module)+ ;
    Program:                 SHEBANG Critic? USE_RPERL Header Critic* Include* Constant* Subroutine* Operation+ ;
    ModuleHeader:            Critic? USE_RPERL? 'package' WordScoped ';' Header ;
    Module:                  Package | Class ;
    Package:                 Critic* Include* Constant* Subroutine+ LITERAL_NUMBER ';' ;
    Header:                  'use strict;' 'use warnings;' USE_RPERL_AFTER? 'our' VERSION_NUMBER_ASSIGN;
    Critic:                  '## no critic qw(' WORD+ ')';
    Include:                 USE WordScoped ';' | USE WordScoped OP01_QW ';' ;
    Constant:                'use constant' WORD_UPPERCASE OP20_HASH_FATARROW TypeInnerConstant Literal ';' ;
    Subroutine:              'our' Type VARIABLE_SYMBOL '= sub {' SubroutineArguments? Operation* '}' ';' ;
    SubroutineArguments:     LPAREN_MY Type VARIABLE_SYMBOL (OP21_LIST_COMMA MY Type VARIABLE_SYMBOL)* ')' OP19_VARIABLE_ASSIGN '@_;' ;
    Class:                   'use parent qw(' WordScoped ')' ';' Include Critic* Include* Constant* Properties MethodOrSubroutine* LITERAL_NUMBER ';' ;
    Properties:              'our hashref $properties' OP19_VARIABLE_ASSIGN LBRACE HashEntryProperties (OP21_LIST_COMMA HashEntryProperties)* '}' ';' |
                             'our hashref $properties' OP19_VARIABLE_ASSIGN LBRACE '}' ';' ;
    Method:                  'our' TYPE_METHOD VARIABLE_SYMBOL '= sub {' MethodArguments? Operation* '}' ';' ;
    MethodArguments:         LPAREN_MY Type SELF (OP21_LIST_COMMA MY Type VARIABLE_SYMBOL)* ')' OP19_VARIABLE_ASSIGN '@_;' ;
    MethodOrSubroutine:      Method | Subroutine;

Code Examples:

CompileUnit

Class

B.4.2: Operations

[[[ SYNTAX PRODUCTION RULES, OPERATIONS ]]]

    Operation:               Expression ';' | OP01_NAMED_SCOLON | OP10_NAMED_UNARY_SCOLON | Statement ;
    Operator:                LPAREN OP01_PRINT FHREF_SYMBOL_BRACES ListElements ')' |
                             OP01_NAMED SubExpression | LPAREN OP01_NAMED ListElement OP21_LIST_COMMA ListElements ')' |
                             OP01_OPEN MY TYPE_FHREF FHREF_SYMBOL OP21_LIST_COMMA LITERAL_STRING OP21_LIST_COMMA SubExpression |
                             OP01_CLOSE FHREF_SYMBOL | OP03_MATH_INC_DEC Variable | Variable OP03_MATH_INC_DEC | SubExpression OP04_MATH_POW SubExpression |
                             OP05_LOGICAL_NEG SubExpression | OP05_MATH_NEG_LPAREN SubExpression ')' | SubExpression OP06_REGEX_MATCH OP06_REGEX_PATTERN |
                             SubExpression OP07_STRING_REPEAT SubExpression | SubExpression OP07_MATH_MULT_DIV_MOD SubExpression |
                             SubExpression OP08_MATH_ADD_SUB SubExpression | SubExpression OP08_STRING_CAT SubExpression | SubExpression OP09_BITWISE_SHIFT SubExpression |
                             OP10_NAMED_UNARY SubExpression | OP10_NAMED_UNARY | SubExpression OP11_COMPARE_LT_GT SubExpression |
                             SubExpression OP12_COMPARE_EQ_NE SubExpression | SubExpression OP13_BITWISE_AND SubExpression |
                             SubExpression OP14_BITWISE_OR_XOR SubExpression | SubExpression OP15_LOGICAL_AND SubExpression | SubExpression OP16_LOGICAL_OR SubExpression |
                             SubExpression OP17_LIST_RANGE SubExpression | SubExpression OP18_TERNARY VariableOrLiteral COLON VariableOrLiteral |
                             OP22_LOGICAL_NEG SubExpression | SubExpression OP23_LOGICAL_AND SubExpression | SubExpression OP24_LOGICAL_OR_XOR SubExpression ;
    OperatorVoid:            OP01_PRINT (STDOUT_STDERR)? ListElements ';' | OP01_PRINT FHREF_SYMBOL_BRACES ListElements ';' |
                             OP01_NAMED_VOID_SCOLON | OP01_NAMED_VOID_LPAREN ListElements? ')' ';' | OP01_NAMED_VOID ListElements ';' | 
                             OP01_NAMED ListElement OP21_LIST_COMMA ListElements ';' | OP19_LOOP_CONTROL_SCOLON | OP19_LOOP_CONTROL LoopLabel ';' ;
    Expression:              Operator | WORD_UPPERCASE LPAREN ')' | CONSTANT_CALL_SCOPED | WordScoped LPAREN ListElements? ')' |
                             Variable OP02_METHOD_THINARROW LPAREN ListElements? ')' | WordScoped OP02_METHOD_THINARROW_NEW ')' ;
    SubExpression:           Expression | 'undef' | Literal | Variable | ArrayReference | ArrayDereference | HashReference | HashDereference | LPAREN SubExpression ')' ;
    SubExpressionOrInput:    SubExpression | FHREF_SYMBOL_IN | STDIN;
    SubExpressionOrVarMod:   SubExpression | VariableModification;
    Statement:               Conditional | (LoopLabel COLON)? Loop | OperatorVoid | VariableDeclaration | VariableModification ';' ;
    Conditional:             'if' LPAREN SubExpression ')' CodeBlock ('elsif' LPAREN SubExpression ')' CodeBlock)* ('else' CodeBlock)? ;
    Loop:                    LoopFor | LoopForEach | LoopWhile ;
    LoopFor:                 'for' MY TYPE_INTEGER VARIABLE_SYMBOL LPAREN SubExpression OP17_LIST_RANGE SubExpression ')' CodeBlock |
                             'for' LPAREN_MY TYPE_INTEGER VARIABLE_SYMBOL OP19_VARIABLE_ASSIGN OpNamedScolonOrSubExp VARIABLE_SYMBOL OP11_COMPARE_LT_GT OpNamedScolonOrSubExp SubExpressionOrVarMod ')' CodeBlock ;
    LoopForEach:             'foreach' MY Type VARIABLE_SYMBOL LPAREN ListElements ')' CodeBlock ;
    LoopWhile:               'while' LPAREN SubExpression ')' CodeBlock | 'while' LPAREN_MY Type VARIABLE_SYMBOL OP19_VARIABLE_ASSIGN SubExpressionOrInput ')' CodeBlock;
    CodeBlock:               LBRACE Operation+ '}' ;

Code Examples:

Operation

Operator

OperatorVoid

Expression

SubExpression

SubExpressionOrInput

Statement

B.4.3: Variable Data

[[[ SYNTAX PRODUCTION RULES, VARIABLE DATA ]]]

    Variable:                VariableSymbolOrSelf VariableRetrieval* ;
    VariableRetrieval:       OP02_ARRAY_THINARROW SubExpression ']' | OP02_HASH_THINARROW SubExpression '}' | OP02_HASH_THINARROW WORD '}' ;
    VariableDeclaration:     MY Type VARIABLE_SYMBOL ';' | MY Type VARIABLE_SYMBOL OP19_VARIABLE_ASSIGN OpNamedScolonOrSubExpIn | 
                             MY Type VARIABLE_SYMBOL OP02_ARRAY_THINARROW SubExpression ']' OP19_VARIABLE_ASSIGN 'undef' ';' | MY TYPE_FHREF FHREF_SYMBOL ';' ;
    VariableModification:    Variable OP19_VARIABLE_ASSIGN SubExpressionOrInput | Variable OP19_VARIABLE_ASSIGN_BY SubExpression ;
    ListElements:            ListElement (OP21_LIST_COMMA ListElement)* ;
    ListElement:             SubExpression | TypeInner SubExpression | OP01_QW | ARGV;
    ArrayReference:          LBRACKET ListElements? ']' ;
    ArrayDereference:        '@{' Variable '}' | '@{' TypeInner? ArrayReference '}' ;
    HashEntry:               VarOrLitOrOpStrOrWord OP20_HASH_FATARROW TypeInner? SubExpression | HashDereference | ENV ;
    HashEntryProperties:     OpStringOrWord OP20_HASH_FATARROW TypeInnerProperties ;
    HashReference:           LBRACE HashEntry (OP21_LIST_COMMA HashEntry)* '}' | LBRACE '}' ;
    HashDereference:         '%{' Variable '}' | '%{' TypeInner? HashReference '}' ;

Code Examples:

ListElement

B.4.4: User-Defined Words

[[[ SYNTAX PRODUCTION RULES, USER-DEFINED WORDS ]]]

    WordScoped:              WORD | WORD_SCOPED ;
    LoopLabel:               WORD_UPPERCASE ;
    Type:                    WORD | WORD_SCOPED | TYPE_INTEGER ;
    TypeInner:               MY Type '$TYPED_' OpStringOrWord OP19_VARIABLE_ASSIGN ;
    TypeInnerProperties:     MY Type '$TYPED_' OpStringOrWord OP19_VARIABLE_ASSIGN SubExpression | 
                             MY Type '$TYPED_' OpStringOrWord OP02_ARRAY_THINARROW SubExpression ']' OP19_VARIABLE_ASSIGN 'undef' ;
    TypeInnerConstant:       MY Type '$TYPED_' WORD_UPPERCASE OP19_VARIABLE_ASSIGN ;
    VariableOrLiteral:       Variable | Literal ;
    VarOrLitOrOpStrOrWord:   Variable | Literal | OpStringOrWord ;
    VariableSymbolOrSelf:    VARIABLE_SYMBOL | SELF ;
    Literal:                 LITERAL_NUMBER | LITERAL_STRING ;
    OpNamedScolonOrSubExp:   OP01_NAMED_SCOLON | OP10_NAMED_UNARY_SCOLON | SubExpression ';' ;
    OpNamedScolonOrSubExpIn: OP01_NAMED_SCOLON | OP10_NAMED_UNARY_SCOLON | SubExpressionOrInput ';' ;
    OpStringOrWord:          OP24_LOGICAL_OR_XOR | OP23_LOGICAL_AND | OP22_LOGICAL_NEG | OP19_LOOP_CONTROL_SCOLON | OP19_LOOP_CONTROL | OP12_COMPARE_EQ_NE |
                             OP11_COMPARE_LT_GT | OP10_NAMED_UNARY | OP08_MATH_ADD_SUB | OP07_MATH_MULT_DIV_MOD | OP07_STRING_REPEAT | OP01_NAMED | OP01_CLOSE | 
                             OP01_OPEN | OP01_NAMED_VOID | OP01_PRINT | WORD ;

There are no additional code examples for this section, all pertinent examples are contained in the previous sections.


APPENDIX C: BEYOND THE ROADRUNNER

Intermediate RPerl

The Scallion Book


Mastering RPerl

The Sword Book


SEE ALSO

RPerl

rperl


AUTHOR

William N. Braswell, Jr.

mailto:william.braswell@NOSPAM.autoparallel.com