Perl Weekly Challenge #217 - Flattening the Matrix

This week we have a very simple challenge! Again due to time, I just did the first challenge this week, but I have an idea of how I'd solve the second and I'll compare with the way others implemented it.

Anyway, to the challenge. The goal is to find the 3rd smallest element of a matrix. The simplest way is simply to flatten, sort, and pick the element. There might be absolutely more performant ways to do it, such as scanning the entire matrix once and keeping a list of the lowest three as you iterate, but this is a case where I feel that it's simply not worth it. One pass to flatten and one sort isn't worth all the extra implementation complexity. I do look forward to seeing any solutions including that technique though.

Here's my code:

Perl Weekly Challenge 257: Smaller than Current

These are some answers to the Week 257, 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 February 25, 2024 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: Smaller than Current

You are given a array of integers, @ints.

Write a script to find out how many integers are smaller than current i.e. foreach ints[i], count ints[j] < ints[i] where i != j.

Example 1

Require in Perl, what should I pay attention?

Hi ! Everyone there ! How are you ?
I am a Perl script programmer for business Server at /cgi-bin/. Recently I moved my Server from Perl 5.8.8. (Fedora Code 7) to Perl 5.32.1 (Rocky9.1).

After the movement a pair of Perl scripts (script_main.pl and script_sub.pl), in which I integrated the minor script_sub.pl into the main part (script_main.pl) by using "require".

In the main script_main.pl, I just inserted the following line,

require 'script_sub.pl';

By this way, two scripts worked as if one. While Perl version was 5.8.8. (Redhat Fedora Core 7) this way worked.

However, it appeared that when in Perl 5.32.1 (Rocky9.1) it encountered an error. I studied a little bit of Perl 5.32.1. There are "require", "use", and "import" as possible vocabulary. In my case, it is just joining two pieces of Perl code by the way of "require". What do you suggest in order to chop down into two pieces from a long full Perl script code CGI, and then to join them together ?

Thanks for your help !

Perl Toolchain Synergy

2023 has been a very Perl-centric year for me so far!

These days I spend a lot of time in Toronto. Back in January when I heard that the TPRC conference would be held there I joined the planning group post-haste. They still needed a venue and I helped them find the perfect one. We'll be right in the middle of the best part of that great city. I encourage you all to come. This one's gonna be great!

Around the same time, TINITA told me that the Perl Toolchain Summit was happening again in Lyon again (first since 2019). I really needed to reunion with my Perl family, so I bugged BOOK until he said "Come on over".

This week in PSC (106) | 2023-05-05

Porters,

After a meeting around an actual physical table at the Perl Toolchain Summit last week, the three of us were back to our regular video calls. The call was longer than usual, as we delved into the code of CPAN.pm.

Perl Weekly Challenge 256: Merge Strings

These are some answers to the Week 256, 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 February 18, 2024 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: Merge Strings

You are given two strings, $str1 and $str2.

Write a script to merge the given strings by adding in alternative order starting with the first string. If a string is longer than the other then append the remaining at the end.

Example 1

Input: $str1 = "abcd", $str2 = "1234"
Output: "a1b2c3d4"

Example 2

Input: $str1 = "abc", $str2 = "12345"
Output: "a1b2c345"

Example 3

Welcome to the Perl Toolchain Summit 2023

This post is adapted from my notes and recollection of the welcome speech I gave on the morning of Thursday April 27, 2023, just before the initial stand-up.

logo-booking.png

This post is brought to you by Booking.com, the Diamond sponsor for the Perl Toolchain Summit 2023.

Booking.com is proud to sponsor the 2023 Perl Toolchain Summit as Perl continues to be a vital piece of our technology stack. We continue to rely on the Perl platform and tooling to serve millions of customers every day, helping them experience the world. Other than our interest in the evolution and modernization of the platform and tooling, the PTS is also a great opportunity to connect with the larger community and share learnings about how other companies and projects are tackling the challenges of working with Perl at scale (talking about both in systems and teams scalability), and how Perl fits an ever-changing and diverse technological landscape in other organizations.

You can learn more about booking at the end of this article.

Early May Perl Software Releases 2023

This is not exhaustive at all and is based on github release notifications rather than MetaCPAN recent. If your perl project uses github releases please let me know so I subscribe to them. I also post them to Perl Programmers.

EPrints 3.4.5-rc1

EPrints is a document management system aimed at Higher Educational institutions and individuals. EPrints has been used to provide Open Access to research results, sharing of educational resources and providing portfolios of work. It has a flexible metadata and workflow model to support varied business needs as well as interaction with other Web and institutional systems.

EPrints 3.4.5 release candidate 1
is now available on GitHub. Full release is planned for release shortly.

Request Tracker 5.0.4

RT is an enterprise-grade issue tracking system. It allows organizations
to keep track of what needs to get done, who is working on which tasks,
what's already been done, and when tasks were (or weren't) completed.

Perl Weekly Challenge #215 - Bad Words and Looking For Zeros

Hello everybody! Back this week for weekly challenge 215, where we look for unsorted words and sets of zeros. This week both challenges took me only about 10-15 minutes each. The usual disclaimer about an early post, so don't read spoilers if you want to do the challenge yourself.

Odd One Out

This one's a very simple task to print the number of words that are not alphabetically sorted. Here's the code:

#!/usr/bin/perl

use strict;
use v5.24;

my $removed = 0;
foreach (@ARGV) {if ($_ ne join('', sort(split(//, $_)))) {$removed++}}
say $removed;

Perl Weekly Challenge 256: Maximum Pairs

These are some answers to the Week 256, 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 February 18, 2024 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: Maximum Pairs

You are given an array of distinct words, @words.

Write a script to find the maximum pairs in the given array. The words $words[i] and $words[j] can be a pair one is reverse of the other.

Example 1

Input: @words = ("ab", "de", "ed", "bc")
Output: 1

There is one pair in the given array: "de" and "ed"

Example 2

The Perl Toolchain Summit 2023

After a break of four years, it has been my privilege to attend the 13th Perl Toolchain Summit (née Perl QA Hackathon). This is the third time the summit has been held in Lyon and the tenth summit I have been able to attend. PTS is a really important event in the Perl calendar where those working on the Perl toolchain and in Perl QA get to meet together for four days of discussions, decisions on the future of Perl, and hacking.

Arriving late on Wednesday evening, I had an overfull list of things I wanted to talk to people about and work I wanted to do. In the end I didn't even get half way though my list, but that was expected.

This week in PSC (105) | 2023-04-28

Today, the PSC met up … in person! We’re all in Lyon for the Perl Toolchain Summit.

psc-2023-04-28.jpg

Meantime, although we had a very long conversation, it boils down to just a couple things:

  • We talked a very long time (well, 45m) about GitHub issues labeled “BBC” and marking them “needs triage” (meaning: more info) or “not a release blocker” or “release blocker”. This will require more work, but we made good progress.
  • We discussed HTTP::Tiny, security, and how best to bootstrap CPAN and stay secure. More soon.
  • We discussed Test2 in core, which is now its own thread on p5p, enjoy!

Perl Weekly Challenge #214 - Rank Score

Just one weekly challenge entry this week, because I am lacking in time and have no idea how to efficiently solve the second challenge.

So here goes:

Rank Score

First, the code:

Perl Weekly Challenge 255: Most Frequent Word

These are some answers to the Week 255, 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 February 11, 2024, 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 Word

You are given a paragraph $p and a banned word $w.

Write a script to return the most frequent word that is not banned.

Example 1

Input: $p = "Joe hit a ball, the hit ball flew far after it was hit."
       $w = "hit"
Output: "ball"

The banned word "hit" occurs 3 times.
The other word "ball" occurs 2 times.

Example 2

Dot Your Environment

Env::Dot

In the category of “scratching my itch”.

Background

An app’s config is everything that is likely to vary between deploys (staging, production, developer environments, etc). The Twelve-Factor App

Storing the often changing parts of configuration in environment variables is one of the principles of The Twelve-Factor App.

From this principle follows the need to store those environment variables and their values in an easily accessible way. Hence, every developer maintains his or her own project specific .env files next to the project files in the same directory where they are used, for instance, when running locally or testing locally.

Yet Another Dotenv Solution

As if we didn’t have these enough already…

What is different with this one, except the name Env::Dot?

Flexibility in input

This week in PSC (104) | 2023-04-21

All three of us met, having skipped last week.

There wasn’t much to talk about because code freeze ahead of 5.38 is in effect, so there isn’t much going on.

  • We talked further about the upcoming deprecations scheduled for 5.38.0 (smartmatch, tick-as-package-separator), and concluded that we remain committed to keeping them deprecated on the current schedule.

  • Next week’s meeting will be in person in the French city of Lyon.

Perl Weekly Challenge #212 - Spinning Letters and Chopping Numbers

Back already with this week's solutions to the PWC #212. Spoiler alert, because the challenge doesn't close for another few days if you want to have a try.

Challenge #1 - Spinning Letters

This week we've got a simple letter rotation. Take each letter of the word provided and rotate it by each number in the list. At first I thought this would be a lot longer code. i even put it in a sub. That actually doubles the size though for absolutely no benefit, so I just simplified. We split the word, then loop through the letters and apply the rotation. If it wraps we start from the start of the alphabet. Upper-case is handled with a simple test to insert the right case of each character. Then we don't even bother putting the word back together again because we can just say it as-is.

Perl Weekly Challenge 255: Odd Character

These are some answers to the Week 255, 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 February 11, 2024 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: Odd Character

You are given two strings, $s and $t. The string $t is generated using the shuffled characters of the string $s with an additional character.

Write a script to find the additional character in the string $t.

Example 1

Input: $s = "Perl" $t = "Preel"
Output: "e"

Example 2

Input: $s = "Weekly" $t = "Weeakly"
Output: "a"

Example 3

Data::Table - Weekly Travelling in CPAN

Destination: Data::Table
Date of Latest Release: Feb 12, 2020
Distribution: Data-Table
Module version: 0.38
Main Contributors: Yingyao Zhou (EZDB), Guangzhou Zou
License: [perl]


Near the Christmas in 2022, I played a data engineering challenge called "Hanukkah of Data 5783". You can find it on https://hanukkah.bluebird.sh/5783 . Players can download data of either .CSV, .JSON or .SQLITE format.

The first* task is like this:

... And their phone number was their last name spelled out. I didn’t know what that meant, but apparently before there were smartphones, people had to remember phone numbers or write them down. If you wanted a phone number that was easy-to-remember, you could get a number that spelled something using the letters printed on the phone buttons: like 2 has “ABC”, and 3 “DEF”, etc."

* There is a "zeroth" task on the calendar year.


I didn't mind perish my skill on SQL, but these kinds of things immediately I thought of Perl, maybe there would be a subroutine like this:

Reinvent the REST

The other day I was working on yet another side project. Almost immediately I got side tracked. Does that make the new project a side side project?

What shiny bobble or cool new tech got my attention you ask? It wasn't $buzzword, or $fancy_tech. Nawe, nothing that resumé worthy. Instead, I decided to see what a MVP for a REST API would look like in using Catalyst. Look ma, no extra modules! Except a JSON one, but I don't count it since Catalyst also uses a JSON module.

NOTE: If you are trying to be productive, you probably want to just use Catalyst::Action::REST instead of rolling your own. That's what I've used at work with great success.

Other than generating the scripts I went ahead and hand wrote out everything else and was pleasantly surprised. There was so little code that I went ahead and retyped the only three modules needed here. Apologies if there's a typo.

Onward to the MVP!

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.