#define Perl: \
I-------------------------------------------------\
I-------------------------------------------------\
I-------------------------------------------------\
I /$$$$$$$ /$$ \
I | $$__ $$ | $$ \
I | $$ \ $$ /$$$$$$ /$$$$$$ | $$ \
I | $$$$$$$
I | $$____/| $$$$$$$$| $$ \__/| $$ \
I | $$ | $$_____/| $$ | $$ \
I | $$ | $$$$$$$| $$ | $$ \
I |__/ \_______/|__/ |__/ \
i-------------------------------------------------\
i-------------------------------------------------\
i-------------------------------------------------i
yyy:
https://www.mcmillen.dev/sigbovik/
man 1 perl
"One thing that distinguishes Perl\
from other languages is its use of sigils;" - official documentation
"There’s more than one way to do it." - motto
• interpreted language
• dynamic typing
• legendary for being unreadable when written by monsters
• sits somewhere between a shell with lots of builtins and python
• very expressive
• it is a better PHP; whatever you are doing with PHP, Perl could do it twice as well
• concise
• no odd restrictions on the syntax
• hackable (in the MIT sense)
• can become hard to read or maintain
Files:
.pl : perl script
.pod : perl documentation file
.tt : perl::Template template file
Programs:
perl <script> <arguments> : interpreter
cpan : "Comprehensive Perl Archive Network"; dependency manager
cpanp : "CPAN Plus"; unstable and bloated cpan alternative
cpanm : "CPAN Minus"; minimalistic CPAN alternative
reply : "REPL Yay"; repl for perl; from the package Reply
perldoc : man like tool for perl documentation (see BELOW)
Documentation:
man 1 perldoc
perdoc <module|subject>
perdoc -f <function>
• designed after man
• you are recommended to set ${PERLDOC_PAGER} to ${MANPAGER}
POD:
• "Plain Old Documentation"
• roff like format with perl spicing
• significantly more readable than roff
Comments:
# single line comment
Semicolons:
<statement>;
• required (except after the last statement)
Pragmas:
use <pragma>
no <pragma>
strict : make some unsafe constructs into errors; generally recommended
warnings : report additional diagnostics
Variables:
my <sigil><name> [assignment]
<sigil><name>
• the keyword "my" is only required with the strict pragma on
sigil:
• signals the type of value we are using
$ : primitive or object
@ : array
% : hash (map)
& : subroutine
* : type glob
my $var;
my $number = 10;
my @array = ($number, $number, $number);
my %map = (ten => $number, also_ten => $number);
Literals:
String:
"<...>" : interpolating string
'<...>' : non-interpolating string
<sigil><name> : variable interpolation
<sigil>{<name>} : unambiguous variable interpolation
— function call interpolation is not directly supported:
• however array literals are expended and evaluated inside
unambiguous variable interpolation
• this allows for the following trick
print "@{ [time] }"
# Example Out: 1742495945
# (time is a builtin function that returns UNIX time)
Misc:
[<element*>] : array
(<element>*) : map
Functions:
sub [name] { <...> }
• "SUBroutine"
• when a name is not specified, it acts as a lambda
Replacing:
s/<...>/<...>/<flag>*
• sed. its literally inline sed
Shells:
`<command>` : executes a command and returns its captured output
qx<d><command><d> : exactly like above, but could be easier to search for in the code
and you can choose your delimiter { "{}", "()" }
system(<command>) : execute a command and return its exit code;
the output of the command is appended to the processes output
Regex:
• Perl is famous for its great regular expression system
• other languages often have libraries that implement Perl compatible regex-es,
or "PCRE" as its commonly referred to
Libraries:
use <library>
Template:
use Template;
perldoc Template
— supports:
• logic
• loops
• including
• very versatile, can be used to preprocess just about anything
• the syntax is clean and readable