A whirlwind review of Perl advent calendars for 2018
Overview
- the Perl Advent Calendar 2018
- The Perl 6 Advent Calendar 2018
- The Perl 6 One-liner Advent Calendar 2018
There were some other Perl-related advent calendars as well:
Perl Advent Calendar
The Perl 5 Advent Calendar, sometimes managed by Jerrad Pierce, this year run by Mark Fowler.
My highlights
- Day 2: Perl in the Browser; the WebPerl project
- Day 5: Santa’s deepdive in an ocean of stockings; Data::Rmap
- Day 21: Debug Hard; Devel::hdb
WebPerl
Hauke D is working on a really cool project that lets you use Perl in webpages (as a kind of Javascript replacement). This is done through the magic of WebAssembly and Emscripten.
I had a really cool plan for a demo here, but I couldn't manage to get it compile properly (once I do, if I can make it work, I will update this later).
Data::Rmap
A handy module that will recurse through a data structure, and run a code block on it. This (may) simplify handling complex data structures.
Devel::hdb
A web-based debugger for Perl. Because everything is available via REST, you can then interact with the debugger from another program, if you want to try automating debugging?
It isn't perfect: in particular, at least in Safari, it's a bit unsteady with showing you particular variables, and you can't look only at a particular key of a hash.
However, it looks interesting, and the REST/JSON-ability is intriguing.
Quick cool things I want to remember…
- Day 4: Christmas Quoting; B::perlstring
- Day 11: Mu; Mu (MooX::ShortHas)
- Day 15: Spot The Difference; App::ccdiff
- Day 16: Handling complex data structures; Hash::Flatten
B::perlstring
Perl ships with the B
module, which interacts with the Perl compiler, and lets you do weird magical things.
One (small) utility is the perlstring()
function, which properly escapes a (potentially) weird scalar, without having to interact with Data::Dumper
or similar modules.
I don't think I will ever use this, because I pretty much always have Data::Dump
available, but it's an interesting tidbit.
Mu
This is purely a syntactic-sugar module. Here is the core of the source code:
sub import { my $caller = caller; $_->import::into( $caller ) for qw( Moo MooX::ShortHas ); }
MooX::ShortHas
provides shorter versions of the has
keyword with the common defaults, so that you don't have to type quite as much boilerplate.
Next time I try to write Moo
-style object-oriented code, hopefully I'll remember to try this out.
Mu; Mu (MooX::ShortHas)
App::ccdiff
Mostly, I just wanted to point to this youtube video: Perl Conference in Glasgow talk. It's almost an hour, so we don't have time to watch it here, but it's a fun little talk.
Hash::Flatten
I'm convinced that I have run into this problem before, and would have used this module. Sadly, I can't remember the details.
It takes a multi-level data structure, and joins up all of the keys until you get a single-level one. It can also unflatten.
Everything
Day | Topic |
---|---|
1 |
Sign o’ The Times; Calendar::List Generate lists of dates, aimed at things re-occuring weekly. |
2 |
Perl in the Browser; the WebPerl project Use Perl to do JavaScript-y things! |
3 |
REST API and the Baby; Cpan::JSON::XS::Type Make sure your data serializes to JSON properly by explicit typing. |
4 |
Christmas Quoting; B::perlstring A “built-in” way to safely dump a string. |
5 |
Santa’s deepdive in an ocean of stockings; Data::Rmap Apply |
6 |
Sticky Delight; Array::Sticky Array::Sticky::INC Make the heads of arrays “sticky”, even through |
7 |
Convert CSV to Pivot Table; Text::CSV::Pivot Pivot your CSV files. |
8 |
DBD::mysql versus DBD::MariaDB; DBD::MariaDB When to use DBD::MariaDB instead of DBD::mysql. |
9 |
CLI program to transform modern function signatures into the older style. |
10 |
Christmas Tree Babbles; Babble A Perl transpiler, similar to the Javascript Babel tool. Still experimental. |
11 |
Mu; Mu (MooX::ShortHas) Syntactic sugar to reduce the overhead of declaring |
12 |
Growing Christmas Trees; SVG SVG::ChristmasTree Use the |
13 |
Lost in legacy arguments; Sub::Params Let functions support either positional or named parameters at the same time. |
14 |
Asynchronous code, using Future. |
15 |
Spot The Difference; App::ccdiff Do character-by-character diffs. |
16 |
Handling complex data structures; Hash::Flatten Flatten nested data structures to one level. |
17 |
Christmas Tunes!; OAuth::CmdLine::Spotify Allow CLI programs to authenticate against Spotify. |
18 |
Test/Compare Your Excel; Test::Excel Determine if two Excel workbooks are the same. |
19 |
Cute Christmas Animals; Mojo::Promise Web programming with Promises, instead of Futures |
20 |
A crazy system that, mostly, lets you run linux on your iPhone. (In a userland i386 emulator…) |
21 |
A debugger, with an HTTP/REST front end. |
22 |
Validation; Method::ParamValidator A module that can be used to ensure that method parameters are valid. |
23 |
Legacy code strikes again; Context::Singleton A module that provides (I think) something similar to |
24 |
Watching the Perl Conference Again; App::HTTPThis App::HTTPSThis CLI programs to serve directories via HTTP and HTTPS. |
25 |
A summary of contributors and links to other advent calendars. |
Perl 6 Advent Calendar
My highlights
Porting a program
A nice recapitulation of porting a program from Perl 5 to Perl 6.
Perl6 in browser
This day (7) in the calendar is ostensibly about Cellular Automata. Cool as cellular automata are, though, I think the really interesting thing here is 6pad.
It's a bit slow, and still in development, but it works.
Some other work in this area includes rakudo.js (see also here), and Webperl (from above) also includes some Perl 6 support (by incorporating Rakudo.js).
jmp
If you do a lot of programming in the terminal, the jmp
program might be interesting? It's a front-end to things like grep
, ack
, etc., that will then jump directly into your editor. It can also parse things like error messages, test errors, etc.
Fancy comments
Perl 6 adds "declarator blocks" to POD declarator blocks.
The MAIN
subroutine uses these comments when it auto-generates the usage
message, so you can slightly customize the help message in this way.
There is also discussion of using multi-method MAIN
to handle various options, the hidden-from-USAGE
trait, and the %*SUB-MAIN-OPTS
variable.
Everything
Day | Topic |
---|---|
1 |
Porting Vigilance, integrating Perl 6 with standard tools Porting a script from Perl 5 to Perl 6 |
2 |
Like Perls in a Pod: document everything (and test the documentation) Discusses Perl 6 POD, and some of the programmatic ways to access it. |
3 |
jmp is a CLI program that helps you move from |
4 |
New Perl 6 POD Features for the New Year Doesn't actually have much to do with POD 6 features; this is a discussion of some of the issues run into while trying to implement some missing POD 6 features. |
5 |
A discussion of some interesting things about variables. |
6 |
Lazy and Industrious Elves; Object::Delayed A module that introduces the |
7 |
Creating one-dimensional cellular automata in Perl 6. It rather buries the lede though, which is 6pad — Perl 6 in your* browser. (*: not all browsers work) |
8 |
Make your Perl 6 grammar compact Suggestions for cleaning up grammars, primarily by using multi-methods, multi-tokens, and multi-rules. |
9 |
Let’s get astroPhysical! – Constants in Perl 6 The author of Perl 5 Astro::Constants discusses porting to Perl 6, and how to define a constant in Perl 6. |
10 |
An update to the |
11 |
Testing your Times Tables with Perl 6 A simple Perl 6 program that tests you on your times tables. |
12 |
Mrs. Claus runs into l10n issues, and refactors a grammar to move some logic outside of it. |
13 |
Web server from scratch with Cro and Debian; cro A quick introduction to installing Perl 6 and |
14 |
Designing a (little) Spacecraft with Perl 6 Because LDAP (although not yet), the author starts describing how you can take an ASN.1 specification, and turn it into Perl 6. |
15 |
Building a (little) Spacecraft with Perl 6 Continuing the adventures from yesterday, a description of how some of the roles and multi-methods are set up to handle serializing and de-serializing ASN.1 objects. |
16 |
A discussion of how to use special comments, traits, and multi-methods to make auto-generated usage instructions more powerful. |
17 |
Compiling our way to happiness A descent into possible hypothetical languages or programming paradigms the author would like Perl 6 to support, in order to solve the famed |
18 |
Only a few days after the Perl 5 Advent Calendar, the Perl 6 Advent Calendar tackles creating christmas trees in SVG. Frankly, the Perl 5 one is better, and someone needs to work on the Perl 6 |
19 |
Interactive Desktop Apps; GTK::Simple Creating a simple GUI app in Perl 6, using the GTK toolkit. |
20 |
Propositional combinatorics in Perl 6 A mathematician shows how to use Perl 6 to study something in n-dimensional space, but what exactly I'm not sure. This is all disguised as a discussion about how North Pole elves are conversant with 6d presents, which apparently make children happier than ones they can hold in their 3d hands? |
21 |
A Perl 6 ORM, although still in development. Possibly not working (according to the Wiki). |
22 |
Jonathan Worthington, creator of Cro, and large parts of the current Perl 6 stack, discusses how to test Cro route handlers. |
23 |
The Perl 6 IRC channel has a number of bots (is 17 large?) which do nice things like automate |
24 |
This is about … topic modeling ? … using a module to do “Latent Dirichlet Allocation” ? I think? What is interesting to me are the examples of fetching data with the |
25 |
Some interesting snippets of Perl 6 code that lets you test numbers for amicability, happiness, and two other qualities. |
Perl 6 One-liner Advent Calendar
Andrew Shitov’s advent calendar looking at Perl 6 one-liners.
My highlights
- Day 14: Another solution to Project Euler problem 19
- Day 19: Computing the value of π
Project Euler problem 19
Another solution to Project Euler problem 19
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
From day 13:
And from the comments of day 13:
Then, on day 14, instead of scanning all dates, just scan the first of the months for Sundays:
However, he was getting excited about gather
/take
, and someone noted that map
would work as well:
Calculating π
Based on the formula:
we can calculate π with:
But, you can also create it using the sequence operator:
Finally, in the comments, Damian Conway offers:
( although he prefers it across two lines, because it looks more like the Leibnitz series:
)
Everything
Day | Topic |
---|---|
1 |
|
2 |
Grepping dividable numbers (Project Euler problem 1) |
3 |
|
4 |
Working with big numbers (Project Euler problem 13) |
5 |
|
6 |
Testing palindromic numbers (Project Euler problem 4) |
7 |
And another option for day 2: |
8 |
Adding up even Fibonacci numbers (Project Euler problem 2) |
9 |
|
10 |
Factorial: Rotating a matrix: |
11 |
Solving problem 34 (Project Euler problem 34) |
12 |
|
13 |
How many days in the century match a condition (Project Euler problem 19) |
14 |
Another solution to yesterday’s problem (Project Euler problem 19) An update based on reader comments: |
15 |
Playing with Fibonacci numbers (Project Euler problem 25; Code golf task) Creating a Fibonacci sequence: Project Euler problem 25: index of the first Fibonacci number > 1000 digits: Code golf to print the first 30 Fibonacci characters: In that last one, the missing character is |
16 |
|
17 |
Playing with prime numbers (Project Euler problem 7; code golf) Project Euler problem 7; print the 10001st prime number: Code golf: print prime numbers below 100: The “Ⅽ” character is (which, in un-optimized form is:) |
18 |
|
19 |
or or, from the comments: |
20 |
A review of the |
21 |
|
22 |
|
23 |
|
24 |
(The behaviour of the special variable will be changing, subtly, in 6.d.) |
25 |
Tips and ideas for Perl 6 Golf
|
(26) |