Larry Wall’s Stranger than Fact Talk got me excited about perl6 / raku! I first tried perl a few years ago and liked it. For me it fits in between Bash and python. Bash is great for simple shell scripting but terse syntax and not being a full blown programming language limit its usefulness. I found perl’s shell interop powerful for scripting tasks that benefit from error handling and clear types. I’ve even landed a perl script in my work code base; it handles running e2e tests on local. Oh the joy of JavaScript developer’s reaction when they see perl, 😃.
Raku is the next step in that. It is Perl6 with a new name, keeping the good parts of perl and removing warts to make it more accessible. After spending two days with the language, it delivers on that promise. Before I get into what I built, general thoughts on Raku:
RAKULIB='./helpers/post_analysis/lib' raku ./helpers/post_analysis/bin/post_analysis.raku
worked in the end. Still don’t know why it can’t just look next to the existing file I’m trying to run like node.js.Here is an example showing Reduction metaoperators, similar to a reduce statement. Might seem magic but unlike Bash it worked smoothly for me.
sub draft_posts { $^a + ($^b{'is_draft'} ?? 1 !! 0) };
my $draft_post_total = [[&draft_posts]] @posts;
@posts
is a list of post hash objects?? !!
is a ternarysub
is subroutin aka function$^a
is the first argument$^b{'is_draft'}
is accessing the value of ‘is_draft’ key in the second argument which is a hash map in this caserepo: https://git.sr.ht/~travisshears/hugo-post-analysis
To get to know Raku I set out to answer open questions about my personal site.
Ended up with a script scans over the files/folders and finds the answers.
Example output:
$ post_analysis
Which sections do you want draft count for:
snippets
blog
tags
notes
tutorials
=== OR ===
all
blog
=== Site Analysis ===
English Posts: 69
German Posts: 17
Percentage translated: 24.637681%
Draft Posts: 9
=== Drafts ===
kampenwand
s3 bucket for site plugins
diy temperature monitor
life clock dev log
first six months: coral
Mt Journey
25% of my English posts have been translated to German, not bad! In the coming months I hope to raise that number while still releasing new post.
Might be the new factor but as of right now I’m enjoying Raku. I plan to rewrite my personal site deploy tool in it and create a brew module as the next challenge. I hope you are inspired to give it a try. 👋