Habere’s Corner
Habere-et-Dispertire has shared some new notes on using the raku command:
- Remove leading and trailing whitespace:
raku -ne "put .trim" {{/path/to/file}}
- Extract lines between START and STOP markers (inclusive)
raku -ne '.put if "START" ff "STOP"' {{/path/to/file}}
- Extract lines between START and STOP markers (exclusive)
raku -ne '.put if "START" ^ff^ "STOP"' {{/path/to/file}}
TPRC Submit your Talk
Don’t Miss the Perl and Raku Conference 2026 in Greenville, SC
SAVE THE DATES! Friday through Sunday, June 26-28
Registration is open: https://tprc.us/tprc-2026-gsp
Weekly Challenge
Weekly Challenge #368 is available for your entertainment.
Raku Tips ‘n Tricks
This week, my eye was caught by what looked like a simple question on the IRC (Discord) channels:
my (%a, @b, %c, @d) = (1, 2).map({ |({"a" => 1}, [1]) });
Why does this seeming straightforward list assignment with = (see docs) cause an error?
Odd number of elements found where hash initializer expected:Found 5 (implicit) elements: ...
Let’s tease that apart, say we make the LHS just a single Array @b and then a single Hash %a
my @b = (1, 2).map({ |({"a" => 1}, [1]) });
#OUTPUT say @b; #[{a => 1} [1] {a => 1} [1]]
my %a = (1, 2).map({ |({"a" => 1}, [1]) });
#ERROR
The docs say that list assignment is governed by the LHS – an Array will take all the RHS elements. We can surmise that a Hash will take all the RHS elements – even splitting key, values – and translate them into key => value pairs. Thus the error if presented with an odd number in total.
Despite this frustration, Raku has two ways to make this work:
my (%a, @b, %c, @d) Z= (1, 2).map({ |({"a" => 1}, [1]) });
#-or-
my (%a, @b, %c, @d) := (1, 2).map({ |({"a" => 1}, [1]) });
say {:%a,:@b,:%c,:@d}
#OUTPUT {a => {a => 1}, b => [1], c => {a => 1}, d => [1]}
You can use binding := instead and since the LHS and the RHS have the same data structure this will work. Or you can combine Z (the zip metaoperator) with = (item assignment), like this:
my (a, b, c) Z= (a, b, c);
#turns that assignment into boring
my a = @x[0]; my b = @x[1]; my c = @x[2]
Your contribution is welcome, please make a gist and share via the #raku channel on IRC or Discord.
Questions About Raku
Comments About Raku
- I’d like opinions on this project to facilitate writing EventSourcing by SmokeMachine
- feels like a special container class in #rakulang should be possible by lizmat
- Obligatory Raku:
say 𐄊+ ᮳;by hwayne
New Doc & Web Pull Requests
- add raku CCR panel Steve Roe
New Raku Modules
- DSL::English::EpidemiologyModelingWorkflows, DSL::English::FoodPreparationWorkflows, DSL::Entity::Jobs, Math::GameTheory, DSL::Entity::Foods, DSL::English::DataAcquisitionWorkflows, DSL::Translators by Anton Antonov
Updated Raku Modules
- Recipe::Parser by ohmycloudy
- GnomeTools by Marcel Timmerman
- Physics::Unit, Physics::Measure, App::Crag by Steve Roe
- Data::Dump by Tony O'Dell
- path-utils by Elizabeth Mattijsen
- jmp by github:nige123
- GD::Raw by Various Artistes
- Sparrow6, Sparky by zef:sp1983
- MongoDB::Fast by Zer0-Tolerance
- Data::TypeSystem, LLM::Graph, Data::Translators by Anton Antonov
- Font::FreeType, PDF::Class, CSS::Stylesheet by David Warring
Winding down
A quiet-ish week this week. Kudos to Anton for his productive spurt on the module front. Happy Easter to those who celebrate.
Please keep staying safe and healthy, and keep up the good work! Even after week 62 of hopefully only 209.
~librasteve
