RPerl
view release on metacpan or search on metacpan
lib/RPerl/Learning.pm view on Meta::CPAN
=head3 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;)/
X<br>
=head1 CHAPTER 13: MANIPULATING FILES & DIRECTORIES
=for comment [ INSERT CHAPTER ]
X<br>
=head1 CHAPTER 14: SORTING TEXT VALUES
=for comment [ INSERT CHAPTER ]
X<br>
=head1 CHAPTER 15: ADDITIONAL SPECIAL OPERATORS
=for comment [ INSERT CHAPTER ]
X<br>
=head1 CHAPTER 16: MANAGING OPERATING SYSTEM PROCESSES
=for comment [ INSERT CHAPTER ]
X<br>
=head1 CHAPTER 17: ADDITIONAL ADVANCED TECHNIQUES
=for comment [ INSERT CHAPTER ]
=head2 Section 17.1: SSE Data Structure & 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'
=head3 Section 17.2: Misc & 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;
# ADDITIONAL UNSORTED OPERATORS, HIDDEN FROM VIEW BELOW
=begin comment
%token OP01_NAMED_SCOLON = /(accept;|bind;|binmode;|bless;|break;|chmod;|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;|prototype;|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;|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;
|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;)/
=end comment
=head3 Section 17.3: Type Introspection
C<types()> introspection subroutine
X<br>
=head1 APPENDIX A: EXERCISE ANSWERS
=head2 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.X<br>
The goal of this exercise is to become familiar with the boilerplate (often-repeated template) RPerl C<HEADER> and C<CRITICS> code sections, as well as the basic C<print> operator.X<br>
The first line, starting with C<#!> and called a "shebang", tells the operating system to run this program using Perl.X<br>
The 4 lines in the C<HEADER> section tell Perl to run this program using RPerl, and the C<$VERSION> number may be incremented for each update to this file.X<br>
The line in the C<CRITICS> section, starting with C<##>, tells RPerl to allow hard-coded numeric values (not used in this program), as well as the C<print> operator.X<br>
The last line, in the C<OPERATIONS> section, calls the C<print> operator on a comma-separated list consisting of 2 string literals, which will simply display the text "Hello, World!" followed by a newline character.X<br>
All other lines beginning with C<#> are comments and, along with blank lines, may be safely ignored or removed.X<br>
#!/usr/bin/env 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:
=for rperl X<noncode>
$ rperl -t LearningRPerl/Chapter1/exercise_1-hello_world.pl
Hello, World!
lib/RPerl/Learning.pm view on Meta::CPAN
=item * OP02_ARRAY_THINARROW
precedence 02 infix: thin-arrow, array dereference and retrieval C<-E<gt>[>
=item * OP02_METHOD_THINARROW_NEW
precedence 02 infix: thin-arrow, class constructor C<-E<gt>new(>
=item * OP02_METHOD_THINARROW
precedence 02 infix: thin-arrow, method dereference and call; ex. C<-E<gt>foo> or C<-E<gt>Bar23>
=item * OP05_MATH_NEG_LPAREN
precedence 05 prefix: arithmetic negative C<-(>
=item * OP08_MATH_ADD_SUB
precedence 08 infix: arithmetic add C<+>, subtract C<->, SSE add C<sse_add>, SSE subtract C<sse_sub>
=item * OP11_COMPARE_LT_GT
precedence 11 infix: numeric comparison less-or-equal C<E<lt>=>, greater-or-equal C<E<gt>=>, less-than C<E<lt>>, greater-than C<E<gt>>; string comparison less-or-equal C<le>, greater-or-equal C<ge>, less-than C<lt>, greater-than C<gt>
=item * OP19_VARIABLE_ASSIGN
precedence 19 infix: assign C<=>
=item * OP01_PRINT
precedence 01 prefix void: C<print> or C<printf> to STDOUT, STDERR, or filehandle
=item * OP01_NAMED_VOID_SCOLON
precedence 01 prefix void: "terms and list operators (leftward)" [1] AKA built-ins, no return value; C<croak;>, C<die;>, C<exit;>, C<return;>
=item * OP01_NAMED_VOID_LPAREN
precedence 01 prefix void: same as above, except with parentheses & without semicolon & without die; C<croak(>, C<exit(>, C<return(>
=item * OP01_NAMED_VOID
precedence 01 prefix void: same as above, except accepts argument(s); C<croak>, C<die>, C<exit>, C<return>
=item * OP01_QW
precedence 01 prefix: quote word; ex. C<qw()> or C<qw(foo bar baz)> or C<qw(Foo23 BarBax Ba_z 123)>
=item * OP01_OPEN
precedence 01 prefix: C<open> filehandle
=item * OP01_CLOSE
precedence 01 prefix: C<close> filehandle
=item * OP01_NAMED_SCOLON
precedence 01 prefix: "terms and list operators (leftward)" [1] AKA built-ins; L<List Of All Operators in Perl 5 Source Code|http://perl5.git.perl.org/perl.git/blob/HEAD:/t/op/cproto.t> [2];
without all-uppercase Perl system built-in keywords (C<__DATA__>, C<AUTOLOAD>, C<CHECK>, etc); named unary operators above (C<defined>, C<exists>, etc); and RPerl keywords (C<use>, C<our>, C<my>, C<package>, C<for>, etc);
C<abs;>, C<accept;>, C<atan2;>, C<bind;>, C<binmode;>, C<bless;>, C<break;>, C<chmod;>, C<chomp;>, C<chop;>, C<chown;>, C<chr;>, C<closedir;>, C<cmp;>, C<connect;>, C<continue;>, C<crypt;>, C<dbmclose;>, C<dbmopen;>, C<default;>, C<dump;>, C<each;>, ...
=item * OP01_NAMED
same as above, except without semicolon
=back
=head3 D.2.4: Punctuation & User-Defined Words
C<[[[ LEXICON TOKENS, PUNCTUATION & USER-DEFINED WORDS ]]]>
=over 16
=item * COLON
C<:>
=item * LPAREN_MY
C<(my>
=item * LPAREN
C<(>
=item * LBRACKET
C<[>
=item * LBRACE
C<{>
=item * WORD
lowercase letter followed by optional word characters; or uppercase letter followed by at least one lowercase letter and optional word characters; ex. C<foo> or C<foo23> or C<Foo23>
=item * WORD_UPPERCASE
single uppercase letter, or uppercase letter followed by uppercase letters, numbers, and underscores; ex. C<FOO> or C<FOOBAR_42_HOWDY>
=back
=head2 D.3: Syntax Arity, Fixity, Precedence, Associativity
Operator I<"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 subroutine. An operator or function which accepts 0 input argument...
L<Operator Arity on Wikipedia|https://en.wikipedia.org/wiki/Arity>
Operator I<"fixity"> is the notation form indicating the location of an operator when placed relative to its own input operands. I<"Prefix"> operators are located before their operands, I<"infix"> between operands, and I<"postfix"> after operands. ...
L<Prefix Notation on Wikipedia|https://en.wikipedia.org/wiki/Prefix_notation>
L<Infix Notation on Wikipedia|https://en.wikipedia.org/wiki/Infix_notation>
L<Postfix Notation on Wikipedia|https://en.wikipedia.org/wiki/Postfix_notation>
Operator I<"precedence">, also known as I<"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 nu...
L<Operator Precedence on Wikipedia|https://en.wikipedia.org/wiki/Operator_precedence>
( run in 1.196 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )