A couple very very last-minute solutions to the Weekly Challenge #211. I was crammed for time, so I didn't get to these until the last minute.
Challenge #1
For challenge number 1 I had an idea of the method I would use, but since I've been experimenting with it anyway, I asked ChatGPT for its ideas as well. Because of my lack of time, I wanted to get some help with the design process. ChatGPT is amazing at both developing and describing an algorithm in simple terms to make it understandable. I based my solution somewhat off the AI's algorithm, but I did write it entirely by hand. It's pretty simple, it just iterates across the matrix and makes sure everything matches its diagonal neighbor prior to it.
Another thing you might notice this week is that I actually put my solutions into functions, not just a basic script. Anyways, here it is:
These are some answers to the Week 250, Task 1, of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Task 1: Smallest Index
You are given an array of integers, @ints.
Write a script to find the smallest index i such that i mod 10 == $ints[i] otherwise return -1.
Example 1
Input: @ints = (0, 1, 2)
Output: 0
i=0: 0 mod 10 = 0 == $ints[0].
i=1: 1 mod 10 = 1 == $ints[1].
i=2: 2 mod 10 = 2 == $ints[2].
All indices have i mod 10 == $ints[i], so we return the smallest index 0.
Example 2
Porters,
We had an abbreviated PSC call today, largely due to an unexpected delay.
We discussed offering split-up deprecation categories, so you can no warnings 'deprecated::.xyz' and re-affirmed that we want to do this.
We talked about improving the backcompat of strict-vs-version behavior for use vX where X is older than v5.36 and agreed we’d bring that back, but wanted to discuss more about other related changes to the use-vX code.
First of all, a greeting. I posted an introduction with a notification of intent to take over a module on CPAN, but the maintainer responded to me. I'm Avery, I'm developing SeekMIDI, a small graphical MIDI sequencer. I started it in 2016 and I took a long break from programming entirely, and I've just restarted developing my programming skills again. For starters, I'm working on Perl Weekly Challenges and bug fixes to modules.
Without further ado, here are my solutions to the PWC #208. All solutions are about to be posted, but this could be a spoiler if you're trying to solve it too. I was very pleased this week that I got it down to about 15-25 minutes for each task, so I'm definitely getting more comfortable in Perl again.
First, task 1:
Quoth the fine manual for Template Toolkit:
The DEFAULT directive is similar to SET but only updates variables that are currently undefined or have no "true" value (in the Perl sense).
Nice. Basically, where SET is like the = operator in Perl, DEFAULT is like the ||= operator. Quite useful! If it were, that is. Because the analogy is only superficially true.
These are some answers to the Week 249, Task 1, 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 December 31, 2023 at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.
Task 1: Equal Pairs
You are given an array of integers with even number of elements.
Write a script to divide the given array into equal pairs such that:
a) Each element belongs to exactly one pair.
b) The elements present in a pair are equal.
Example 1
Date of Latest Release: Feb 04, 2023
Distribution: Quiq
Module version: 1.207
Main Contributors: Frank Seitz(FSEITZ)
License: The Artistic License
Source: https://github.com/s31tz/Quiq
Quiq is a "Perl class library for rapid development". The modules are "designed according to uniform principles" (translated from German).
Quiq contains 234 (Ooooops!!!) classes at the time this post is being written and their descriptions are mostly written in German.
It contains several text-based document/markup language code writers, namely Quiq::Tag (for XML), Quiq::Html::MODULES, Quiq::MediaWiki::Markup, Quiq::Css, Quiq::LaTex::MODULES; some network functionalities including Quiq::Http::MODULES, Quiq::Ssh and Quiq::Socket ; some tiny tools like Quiq::Color and Quiq::Stopwatch; some system tools like Quiq::Path, Quiq::TempFile and Quiq::Process; some modules for meta-development including Quiq::Hash and Quiq::Object; some modules for general use like Quiq::Converter, Quiq::Math and Quiq::Epoch. ...
For CSS, we have
Quiq::Css
:
How to learn Perl has been an eternal problem for the Perl community. Compared to many other languages that place an emphasis on teaching the basics and using education as a tool for evangelism we've had sporadic efforts along those lines. Given the size of our community and the fact that the best programmers are often in great demand, we have a hard time pumping out the needed docs and examples.
I've been using ChatGPT quite a lot lately and find that although it makes some mistakes it actually churns out pretty decent Perl if given good instructions. For example here's one I did this AM. We just had the dreaded hour shift here in the US and I'm just not up to thinking so I asked Chat GPT:
"write a perl subroutine that accepts two hashrefs and a list. For each item in the item merge the hashrefs by combining the values into an array ref. "
Here's what it pumped out:
All three of us met, and were joined by Pete Krawczyk who first wanted to discuss some TPRF-related issues.
Following on from this we discussed:
Zefram’s request to back out the strict-vs-VERSION changes. There’s some merit here, he sent a PR to undo the whole thing. We feel there’s two different issues that need looking at separately. Paul will explain some thoughts in more detail.
Yves’s request to reöpen discussions about deprecated:: warning categories. There may be benefit here too. Paul will write a followup response.
These are some answers to the Week 248, Task 2, 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 December 24, 2023, at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.
Task 1: Submatrix Sum
You are given a NxM matrix A of integers.
Write a script to construct a (N-1)x(M-1) matrix B having elements that are the sum over the 2x2 submatrices of A,
b[i,k] = a[i,k] + a[i,k+1] + a[i+1,k] + a[i+1,k+1]
Example 1
Call For Papers is now open! You can submit your talk Ideas at https://tprc.to/papers. Talk submission deadline is March 31 Midnight UTC. Talks must be given live and in-person. If you are looking for any talk ideas, try out the conference wiki.
Visit the TPRC 2023 website at https://tprc.to/
Follow us on Twitter: @PerlConferences
Like us on Facebook: The Perl Foundation (@tpf.perl)
Subscribe to the mailing list: https://tprc.to/subscribe
Post a message to us at https://tprc.to/tprc-2023-tor/contact-us/
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:
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”)
These are some answers to the Week 248, Task 1, 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 December 24, 2023 at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.
Task 1: Shortest Distance
You are given a string and a character in the given string.
Write a script to return an array of integers of size same as length of the given string such that:
distance[i] is the distance from index i to the closest occurrence of the given character in the given string.
The distance between two indices i and j is abs(i - j).
Example 1
In which we ponder the highest bit, and find a much faster Max_XOR.
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:
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.



The above plus more colors and shirt styles are also available!
Buy now at: https://freewear.org/PerlandRaku
These are some answers to the Week 247, Task 2, 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 December 17, 2023, at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.
Task 2: Most Frequent Letter Pair
You are given a string S of lower case letters 'a'..'z'.
Write a script that finds the pair of consecutive letters in S that appears most frequently. If there is more than one such pair, chose the one that is the lexicographically first.
Example 1
Input: $s = 'abcdbca'
Output: 'bc'
'bc' appears twice in `$s`
Example 2
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: