Regexp::Assemble - Weekly Travelling in CPAN

It has been on my mind quite a while. Originally it was suggested on Twitter, by Mohammad Anwar, the maintainer of "The Weekly Challenge", that the community should re-publish the CPAN Weekly, which existed before I joined the hacker community. Our plan was having the newsletter began in December 2022. Actually that collided with the Advent Calendar, so, not a good time. Anyway, after many twists and turns, I was busy in late 2022 and early 2023 for job hunting (settled now). Now I try to act as a tour guide and visit some CPAN modules (or distributions) with you in a causal manner.

Destination: Regexp::Assemble

Date of Latest Release: Jun 20, 2017
Distribution: Regexp-Assemble
Module version: 0.38
Main Contributors: David Landgren and Ron Savage(RSAVAGE)

Regexp::Assemble is used for combining regular expressions.

my $ra = Regexp::Assemble->new;
$ra->add('cat', 'rat');
say $ra->re;
say $ra->as_string;
# (?^:[cr]at)
# [cr]at

The two methods of the module you will probably use most frequently, as_string and re , have subtle differences:

Perl Weekly Challenge 207: Keyboard Word and H-Index

These are some answers to the Week 207 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on March 12, 2023 at 23:59). This blog post offers some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: Keyboard Word

You are given an array of words.

Write a script to print all the words in the given array that can be types using alphabet on only one row of the keyboard.

Let us assume the keys are arranged as below:

Row 1: qwertyuiop
Row 2: asdfghjkl
Row 3: zxcvbnm

Example 1

Input: @words = ("Hello","Alaska","Dad","Peace")
Output: ("Alaska","Dad")

Example 2

This week in PSC (099)

After missing last week, all three of us attended.

  • Recapped the missing weeks from absences
  • Smartmatch deprecation seems to be causing some BBC failures due to new warnings, but that’s to be expected; Philippe to submit patches upstream
  • Refined the questions surrounding SSL-in-core; Paul to send a follow-up email
  • RFC0013 needs some core changes to how overload works; best deferred for 5.39 now
  • Agreed to rename “RFC” to “PPC” (”Proposed Perl Change”)

TWC 205: Exclusive Third Or First

In which we ponder the highest bit, and find a much faster Max_XOR.

Ordering Your Tests

By default, the test actions of both ExtUtils::MakeMaker and Module::Build test t/*.t in lexicographic order (a.k.a. ASCIIbetical order). Under this default, some Perl module authors who want tests performed in a given order have resorted to numbering tests: t/01_basic.t, t/10_functional.t, and so on.

My personal preference is to take the lexicographic ordering into consideration when naming test files: t/basic.t through t/whole_thing.t. But the price of this choice is a certain number of contrived test names, and even the occasional thesaurus lookup.

But there is a better way. Both ExtUtils::MakeMaker and Module::Build allow you to specify tests explicitly.

Under ExtUtils::MakeMaker version 6.76 or above, you call WriteMakeFile() thus:

Perl Weekly Challenge 206: Shortest Time and Array Pairings

These are some answers to the Week 206 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on March 5, 2023 at 23:59). This blog post offers some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: Shortest Time

You are given a list of time points, at least 2, in the 24-hour clock format HH:MM.

Write a script to find out the shortest time in minutes between any two time points.

Example 1

Input: @time = ("00:00", "23:55", "20:00")
Output: 5

Since the difference between "00:00" and "23:55" is the shortest (5 minutes).

Example 2

Perl and Raku Merch from Freewear

Freewear now has Perl and Raku merch featuring Camelia, The Onion Logo and a Camel Shadow. A donation is made to TPRF for each sale.

FW0565.png
FW0571.png
FW0556.png

The above plus more colors and shirt styles are also available!

Buy now at: https://freewear.org/PerlandRaku

Assert Your Environment

Env::Assert

In the category of "scratching my itch".

I was doing some data pipelining and dockerising my creation. And - as always - when testing and devving I forgot to set the right environment variables. And when container image gets passed around, the information about the required env settings will certainly get lost.

Here is something of a solution to that:

How to ensure you have the environment variables and values you need?

Here is a common sight:

$ PLAEC='Stockholm'
$ if [[ "$PLACE" == '' ]]; then echo "Normal OK"; fi
OK

... And the program fails with no errors!

Not quite what we want!

Another example, from a docker container image I created lately:

This Week in PSC (098)

Paul and Philippe attended (Rik is still enjoying Australia).

We discussed:

  • feature-class: there's a soon-to-be-merged PR to fix most memory leaks https://github.com/Perl/perl5/pull/20809
  • n-at-a-time map/grep: HAARG should reply to any remaining open questions, so that we can likely move the RFC to the next step of the process ("Exploratory")
  • SSL in core: it's still not in core, and there's an open PR to just dual-life the SSL modules, but that's unlikely to be the solution we're looking for. Also, we're still looking for a project manager for this project. Enquire Within.
  • RFC0013: awaiting the ability to store more information in the interpreter about overload (for API version and flags)

Perl Weekly Challenge 205: Third Highest and Maximum (Bit-Wise) XOR

These are some answers to the Week 205 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on February 26, 2023 at 23:59). This blog post offers some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: Third Highest

You are given an array of integers.

Write a script to find out the Third Highest if found otherwise return the maximum.

Example 1

Input: @array = (5,3,4)
Output: 3

First highest is 5. Second highest is 4. Third highest is 3.

Example 2

Using Type::Params Effectively

One of the modules bundled with Type::Tiny is Type::Params, a module that allows you to validate subroutine signatures using type constraints. It's one of the more popular parts of the suite.

This article provides a few hints for using it effectively.

ChatGPT suggests new keywords for Perl

I asked ChatGPT to suggest some new keywords that might make Perl more desirable. Here's the dialog:

JOHN: suggest some new keywords that Perl could add to its core syntax that would make the language more desirable to modern programmers

CHATGPT: Perl is a mature language that has undergone significant development since its inception. Despite this, there are always new features that can be added to a language to improve its appeal to modern programmers. Here are some suggestions for new keywords that Perl could add to its core syntax:

async and await: Asynchronous programming has become an increasingly important aspect of modern programming. Adding support for async and await keywords in Perl would enable developers to write non-blocking code that can take full advantage of modern hardware.

let: The let keyword is commonly used in languages like JavaScript and Rust to create variables with a limited scope. Adding let to Perl would make it easier to write clean and concise code.

Outstanding GitHub Items

Recently I received a bump on a GitHub pull request. This surprised me, because I was unaware of anything outstanding. I was even more surprised when I discovered that the distribution in question also had two open issues, one dating back about three months.

I have no idea why I was oblivious to these, but it made me want to audit myself to see if any other distributions had the same problem. GitHub has these nice links at the top of the page, Pull requests and Issues, but these show pull requests and issues that I initiated. I found no obvious way to display pull requests or issues filed against my repositories.

Perl Weekly Challenge 204: Monotonic Arrays and Reshape Matrix

These are some answers to the Week 204 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on February 19, 2023 at 23:59). This blog post offers some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: Monotonic Array

You are given an array of integers.

Write a script to find out if the given array is Monotonic. Print 1 if it is otherwise 0.

An array is Monotonic if it is either monotone increasing or decreasing.

Monotone increasing: for i <= j , nums[i] <= nums[j]

Monotone decreasing: for i <= j , nums[i] >= nums[j]

Example 1

Input: @nums = (1,2,2,3)
Output: 1

Example 2

Input: @nums (1,3,2)
Output: 0

Inevitable Improbabilities

Guys anything can happen. There is literally no way of avoiding something that you haven’t prepared for. So in the face of mounting anxiety over the huge number of unexpected scenarios that may be around the corner, what can you do? You can contemplate insulating yourself, try and minimise the hazards, control your environment to a fine level of detail so that the surprises are infrequent and hazards are mitigated. At work I am drowned in Health and Safety Guidance, IT security protocols, Fire Safety Training. This means that work is to a large extent a somewhat boringly protected environment for me, my colleagues and my patients. Yet, even this can not avoid surprises. So what about your home, sitting in front of your computer. All the protection provided by protocols here are more vague, less policed, seen more as guidelines rather than mandatory.

The worst enemy

What does ChatGPT think about improving Perl?

For kicks I asked GPT to speculate about how we might improve Perl syntax with types and better object orientation. It generated the follow code and descriptions. Yes I know there's some errors in the code, I'm just presenting this as Chat GPT wrote it.

FWIW it looks a lot like what I see coming out of Corrina.

JOHN: If you wanted to improve Perl by adding types and object orientation what would you do. Give an example.

CHATGPT: Perl already has a limited form of object orientation, and there are also ways to add type checking through modules like Type::Tiny and Moose. However, if you were looking to significantly improve Perl's support for types and object orientation, there are a few different directions you could take.

PayProp supports the German Perl/Raku Workshop 2023

PayProp is an automated payment and reconciliation platform specific to the lettings industry that is both easier to use and more powerful than solutions offered by banks and traditional software vendors.

The Perl Toolchain Summit 2023 has a COVID Policy

The Perl Toolchain Summit is the annual event that brings together the key developers working on the Perl toolchain. The 13th summit (after a three year hiatus in 2020-2022) is in France this year, in late April.

It is, at its heart, an in-person event: about thirty people will spend four days in confined spaces, exchanging ideas and patches. And also droplets. To keep everyone safe, we have prepared a COVID policy.

Perl Weekly Challenge 203: Special Quadruplets and Copy Directory (Functional Programming Approach)

These are some answers to the Week 203 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a couple of days from now (on February 12, 2023 at 23:59). This blog post offers some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: Special Quadruplets

You are given an array of integers.

Write a script to find out the total special quadruplets for the given array.

Special Quadruplets are such that satisfies the following 2 rules. 1) nums[a] + nums[b] + nums[c] == nums[d] 2) a < b < c < d

Example 1

Input: @nums = (1,2,3,6)
Output: 1

Since the only special quadruplets found is $nums[0] + $nums[1] + $nums[2] == $nums[3].

Example 2

This week in PSC (097)

PSC met today, just Paul and Philippe.

We discussed:

  • inclusion of TLS libraries in the core: we think we should just try the "dual life" path, and see where that gets us.
  • n-at-a-time map/grep: Paul suspects it's impossible to properly disambiguate my ($var, ...) from the EXPR case, and we wonder if the only choice is between having new keywords and dropping the EXPR case.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.