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
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.
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:
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
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.
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:
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
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”)
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:
These are some answers to the Week 246, 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 10, 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: Linear Recurrence of Second Order
You are given an array @a
of five integers.
Write a script to decide whether the given integers form a linear recurrence of second order with integer factors.
A linear recurrence of second order has the form
a[n] = p * a[n-2] + q * a[n-1] with n > 1
where p
and q
must be integers.
Example 1
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
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:
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)
These are some answers to the Week 246, 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 10, 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: 6 out of 49
6 out of 49 is a German lottery.
Write a script that outputs six unique random integers from the range 1 to 49.
Output:
3
10
11
22
38
49
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.
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.
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.