This Week in PSC (086)

We're trying out new ways to send out these regular announcements of what we get up to on the Perl Steering Council. This will be a regular posting that gives a brief summary of what we discussed in our weekly (or at least, near-weekly, give or take scheduling clashes) meetings.

  • Internals docs (such as perlguts, perlapi) could be done better, but it's unclear how. Some new documents might be useful, but there's a risk of spending too much time on obscure internal specifics that almost nobody will ever need to read about or touch.
  • Smartmatch deprecation continues. Philippe has sent patches to CPAN modules that may be affected. autodie still needs some further work.
  • (As alluded to by this very blog post) we discussed communication strategies for user-facing news announcements. Thoughts are to post here on blogs.perl.org and send links elsewhere - such as Twitter, Reddit, etc.. We don't have a good feel for where folks will find it, so we'll just have to adapt as we go.
  • The module_true branch which implements the RFC is now merged and will be default in use v5.38. This will mean you no longer need to remember that final 1; line at the end of your module file.

Perl Weekly Challenge 190: Capital Detection and Decoded List

These are some answers to the Week 190 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 November, 13, 2022 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: Capital Detection

You are given a string with alphabetic characters only: A..Z and a..z.

Write a script to find out if the usage of Capital is appropriate if it satisfies at least one of the following rules:

1) Only first letter is capital and all others are small. 2) Every letter is small. 3) Every letter is capital.

Example 1

Input: $s = 'Perl'
Output: 1

Example 2

Mystery Buglet #2

Hey! I know, I know: long time, no blog.  I would love to blame the pandemic, but the truth is, I just haven’t been inspired with any sufficiently Perl-y topics lately.  Until recently, when I ran into this.

Now, once upon a time, I wrote a post about a small buglet I had encountered.  The post presented the problem, then asked you if you saw the problem, then explained what was going on.  So let’s do that again.  First, the code:
sub generate_temp_file
{
state $TMPFILES = [];
END { unlink @$TMPFILES }
my $tmpfile = `script-which-generates-tempfile`;
chomp $tmpfile;
push @$TMPFILES, $tmpfile;
return $tmpfile;
}

As before, the actual code does a bit more, but I promise I’ve omitted nothing that’s relevant to the bug.  Do you see it?  If not, click to find out more.

The deep, the shallow and the ugly (classes)

Previously I showed parts of the API of my new module Graphics::Toolkit::Color. This time I want to mention some bits about the code base, which demonstrate what I tried to say long ago (sorry for the long delay i hope I can complete the series).

Meet jp


Welcome

Please welcome the latest JSON tool for the command line: jp!

jp (mostly named from the Mojolicious class Mojo::JSON::Pointer that makes jp possible) is a command line tool for quickly extracting data from a JSON object.  How many times do we get a complex JSON object from some command and we just need to extract a specific set of values from it?  Every time!  All the time!  Often, people use basic tools like grep and sed.  Most people reach for jq, but I find the syntax too cumbersome to use just to extract my desired data.  I just want to use JSON Pointers and move on, but, indeed, sometimes JSON Pointers aren't even enough.  jp really shines with some helpful command line arguments, a regular expression JSON Pointer syntax, and, finally, a Perl eval argument for total power.

Get on with it

Let's see jp work.  Each example explainer links to the JSON Object used for the example.

Here's the most basic use.

$ jp /server/0/password < t/json1.json

REDACTED_APIKEYfalse

Perl Weekly Challenge 189: Greater Character and Array Degree

These are some answers to the Week 189 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 November, 6, 2022 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: Greater Character

You are given an array of characters (a..z) and a target character.

Write a script to find out the smallest character in the given array lexicographically greater than the target character.

Example 1

Input: @array = qw/e m u g/, $target = 'b'
Output: e

Example 2

Input: @array = qw/d c e f/, $target = 'a'
Output: c

Example 3

Sending a simple email

To have a secure SMTP delivery, use Email::Sender. Mail::Sendmail uses SMTP for transport and there's no other type of transport. It does not support SMTP authentication, which my SMTP server now requires even for access from localhost. From what I read and tried once or twice in the past, the current "best practice" or recommended way is to use Email::Sender. Here's an incantation to send mail using sendmail:

use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Sender::Transport::Sendmail qw();
use Try::Tiny;my $email = Email::Simple->create(
header=>[To=>$to, From=>$from,
Subject=>$subject],
body=>$body,
);try {
sendmail($email,
{from=>$from,
transport=>Email::Sender::Transport::Sendmail->new});
} catch {
print "Can't send mail: $_";
}
  • It's easy to switch transport to SMTP (just change two lines).

  • It's easy to add SMTP authentication (just pass arguments to transport constructor).

  • It's easy and clear where to add custom email headers (whereas in Mail::Sendmail, some arguments are "magical"/processed, they do not correspond 1:1 to headers).

  • It's easy to construct multipart email (construct the appropriate $email object).

In addition:

  • Envelope sender and RFC822 From is clearly separated, forcing beginners to understand the concept.

So there you have it, sending an temp email in Perl the modern way. No longer apt for one-liners though.

course change for Kephra

Kephra, an editor for programming (mostly Perl) written in WxPerl is my main project since I stumbled into the Perl community. Most people I know already heard of it - but I want to write about a new development that might be helpful for some, which might consider to use it even if it has a very limited feature set (forth rewrite baby!).

TPF launches merch store for Perl 5

TPF has launched an online store with Perl merchandise (swag) celebrating the Perl 5.36 release. The marketing committee plan to do a custom celebratory collection for each release of Perl with revenue from each sale goes to TPF's Perl fund.

The store includes long- and short-sleeved t-shirts, sweatshirts, hoodies and stickers - all featuring a new Raptor image for the 5.36 release.

800.jpga800.jpg

From: https://news.perlfoundation.org/post/tpf-merch-store

Perl Weekly Challenge 188: Divisible Pairs and Total Zero

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

Task 1: Divisible Pairs

You are given list of integers @list of size $n and divisor $k.

Write a script to find out count of pairs in the given list that satisfies the following rules.

The pair (i, j) is eligible if and only if
a) 0 <= i < j < len(list)
b) list[i] + list[j] is divisible by k

Example 1

Input: @list = (4, 5, 1, 6), $k = 2
Output: 2

Example 2

Input: @list = (1, 2, 3, 4), $k = 2
Output: 2

Example 3

Input: @list = (1, 3, 4, 5), $k = 3
Output: 2

Example 4

My Perl Weekly Challenge

Really, how hard could it be?

All this talk about types, objects, and systems, got me to thinking, "what would it take to create a 100% backwards-compatible pure Perl proof-of-concept for optionally typable subroutine signatures". I mean really, how hard could it be? So I started sketching out some ideas and here's what I came up with:

use typing;

sub greet :Function(string, number) :Return() {
  my ($name, $count) = &_;

  print "Hi $name, you have $count messages waiting ...\n";
}

Class::Plain - Class Syntax for Hash-Based Perl OO

Class::Plain provides a class syntax for the hash-based Perl OO.

Usage

Casting Perls before Splines

As I sit pondering my peas at the dinner table, my thoughts are unnaturally drawn to the similarity between these pulses and Perl. A famous poet once said that "For a hungry man, green peas are more shiny than gleaming pearls". From these green orbs on my plate, the mind drifts to a recent virtual conversation regarding logos, branding, rebirth and innovation in Perl. One wonders whether such heated debates are important, relevant and what it might mean for Perl in the future. The Camel (from the O'Reilly Book on Perl) has long been the image associated with the language, along with the Onion (Origin perhaps from Larry Walls' "state of the onion" presentation). Personally it is not something that I feel passionately about. "Perl, with any other logo would be just as quirky" as Will Shakespeare is reported to have said. But The Camel is the popular, recognisable standard "logo" with some, as yet to be tested, copyright and trademark "issues"

Perl Weekly Challenge 187: Days Together and Magical Triplets

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

Task 1: Days Together

Two friends, Foo and Bar gone on holidays separately to the same city. You are given their schedule i.e. start date and end date.

To keep the task simple, the date is in the form DD-MM and all dates belong to the same calendar year i.e. between 01-01 and 31-12. Also the year is non-leap year and both dates are inclusive.

Write a script to find out for the given schedule, how many days they spent together in the city, if at all.

Example 1

Input: Foo => SD: '12-01' ED: '20-01'
       Bar => SD: '15-01' ED: '18-01'

Output: 4 days

Example 2

London Perl Workshop: Status Update & 2023

Hello all. It's been a while. As you may have guessed there will not be a workshop this year. We spoke about organising one but the uncertainty around restrictions, along with other organisational constraints, resulted in our decision not to.

Types, Objects, and Systems, Oh my!

Inextricably bound

Perl isn't a strongly typed language, and its built-in types are limited and not generally accessible to the engineer, however, Perl supports various classes of data and in recent years has flirted with various ways of enabling runtime type checking.

In a strongly typed language the tl;dr; case for declaring data types is memory management, compile-time code optimization, and correctness. To this day I'm both impressed and horrified by the number of errors caught when I implement some kind of type checking in my programs. When it comes to runtime type checking we're only concerned with enforcing correctness.

Types, values, objects, signatures, and the systems that tie these all together, are all inextricably bound. They are necessarily interdependent in order to present/provide a cohesive and consistent system. Peeling back the layers a bit, types are merely classifications of data. Any given piece of data can be classified as belonging to a particular type whether implicit or explicit.

Type::Tiny v2 is Coming

Eagle-eyed watchers of CPAN may have noticed that I've recently been releasing Type::Tiny development releases with version numbers 1.999_XYZ.

Type::Tiny v2 is intended to be compatible with Type::Tiny v1. If you've used Type::Tiny v1, you shouldn't need to change any code, but Type::Tiny v2 has a few new features which may make your code simpler, more maintainable, and more readable if you adopt them.

Perl Weekly Challenge 186: Zip List and Unicode Makeover

These are some answers to the Week 186 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 Oct. 16, 2022 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: Zip List

You are given two lists @a and @b of same size.

Create a subroutine sub zip(@a, @b) that merges the two lists as shown in the example below.

Example:

Input:  @a = qw/1 2 3/; @b = qw/a b c/;
Output: zip(@a, @b) should return qw/1 a 2 b 3 c/;
        zip(@b, @a) should return qw/a 1 b 2 c 3/;

Zip List in Raku

Look mom I invented colors

Just released Graphics::Toolkit::Color for the purpose to create computationally harmonic color pallets (2-3 lines max for most needs). It is in fact a chunk out of Chart I needed to reuse in other projects as the Harmonograph. And as you can see in the SEE ALSO section of the POD - I'm aware that there are plenty other modules doing, parts, similar stuff or even more.

Hacktoberfest 2022 is near!

Hello Fellow Perl mongers!

Every year in the month of October a company named DigitalOcean hosts an event named Hacktoberfest.

If you ever wanted to contribute to a Perl project now is a good time to give it a go!. Here are a few beginner friendly projects that are up-for-grabs and here is a list of Github projects with the "hacktoberfest' topic.

If you are a project owner and would like someone to participate in your project make sure to add the 'hacktoberfest" topic to a github/gitlab issue and promote your project on ( blogs.perl.org, perl.com/ ,Perlweekly, Perl Reddit , Medium ) or any other channels used to promote your Perl content.

Looking forward to seeing your Hacktoberfest pull requests!

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.