Do you have Perl question?

Here is my response ...

https://theweeklychallenge.org/blog/perl-question

Perl Weekly Challenge 175: Last Sunday and Perfect Totient Numbers

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

Spoiler Alert: This weekly challenge deadline is due in a few of days from now (on July 31, 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: Last Sunday

Write a script to list Last Sunday of every month in the given year.

For example, for year 2022, we should get the following:

Sorting Subroutine Results

The Perl sort built-in is mostly (at least by me) called as sort LIST or sort BLOCK LIST. But there is a third way to call it: sort SUBROUTINE LIST, which actually appears first in the documentation.

This is not a blog entry about using the sort SUBROUTINE LIST form of sort. It is more about the need to be aware of this form when writing (or trying to write) the sort LIST form.

Consider the following situation: you have a subroutine foo() which returns an un-ordered list. You need that list sorted. Perl has a sort built-in, so your (or at least my) first reaction is to write my @sorted = sort foo();, run it, and then wonder why @sorted is empty.

Ideas from TPRC2022: Tools to help refactor large mature code bases

Every Perl gig I have ever had, and from most of the conversations I had at this years Perl and Raku Conference, was working on a large code based that is serving the business and it's customers very well such that the business is profitable (i.e. a mature code base).

This is an enviable position to be in but whilst this software is robust from the outside, there is often a reluctance to make dramatic changes. Unfortunately code that is perceived as too fragile to touch tends to be replaced and replaced in another language.

The PPI + Class::Inspector combination is already being used by people I've spoken too, in bespoke tools to refactor large code bases reliably.

We have frameworks for testing (Test:: etc) and linting (Perl::Critic) with suites of well established reusable polices, so why not a similar framework for refactoring?

Such a tool might have provided polices to assist replacing deprecated syntax, migrate between "Try" implementations, fixing up scalar vs list context, just to name a few.

Decode Hexdump

Please checkout my experience decoding hexdump.

https://theweeklychallenge.org/blog/decode-hexdump

Perl Weekly Challenge 174: Disarium Numbers in dc

This blog is an answer to the first task (Disarium Numbers) of the Week 174 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Originally, the Perl Weekly Challenge called for solutions in Perl and Raku (also known as Perl 6 at the time). But, very soon, people started to provide solutions in other “guest” languages. See for example my blog post providing solutions to the task described below in about 18 different guest languages.

One of the languages I tried for the first time last week with Sylvester’s sequence is dc, and it turned out to be much more difficult and challenging than I initially thought. One of the problems is that there is only very limited documentation on this old programming language. So I thought it might be useful to describe in some details how I solved it. I provided detailed explanations in this other blog post. I’ll now do the same with the disarium number task of this week, which is a bit more complicated.

Scalar Context: Lists Versus Arrays

For a long time after I first encountered Perl, I looked on "list" and "array" as essentially interchangeable concepts. A list was simply the source construct corresponding to an array. This idea is mostly correct. But as they say, the devil is in the details.

One of the differences is what happens to them in scalar context. An array evaluates to the number of elements it contains. A list evaluates to its last element. So:

my @array = qw{ one two five };
say scalar @array;  # prints '3'
{
    no warnings 'void'; # Note the need for this
    say scalar( qw{ one two five } ); # prints 'five'
}

Debrief: Perl IDE Hackathon 2022

perl ide hackathon.png

I had a great time hacking on the Perl Navigator and Raku Navigator as part of the Perl IDE Hackathon 2022. Thank you to everyone who volunteered their time in person or remotely. Thanks especially to Brian for having many github issues ready for people to work on, and for helping so many people understand the concepts of Language Servers. I received compliments that the Hackathon was very organized but truthfully if people got that impression then Brian should get all the credit!

As a community I feel we could do better at helping people getting started and involved, so my goal was to emphasize first time and one off contributions. Brian caught the vision on this and as mentioned, did a great job preparing github issues and spent much of his time getting peoples development environment running. Hopefully he will post a report on what got done in the near future.

Strawberry Perl

Do you want to convert Perl source into .exe?

Please checkout my experience.

https://theweeklychallenge.org/blog/strawberry-perl

Perl Weekly Challenge 174: Disarium Numbers and Permutation Rankings

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

Spoiler Alert: This weekly challenge deadline is due in a few of days from now (on July 24, 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: Disarium Numbers

Write a script to generate first 19 Disarium Numbers.

A disarium number is an integer where the sum of each digit raised to the power of its position in the number, is equal to the number.

For example,

518 is a disarium number as (5 ** 1) + (1 ** 2) + (8 ** 3) => 5 + 1 + 512 => 518

Core Modules: filetest

The filetest pragma modifies the behavior of the file test operators (a.k.a. the -X operators.) It has been in core since Perl 5.6.0.

As of Perl 5.36.0 it still has only one sub-pragma, 'access', which applies to the -r, -w, -x, -R, -W, and -X tests. Normally, these tests only consider the mode bits returned by stat(), as discussed in my previous blog post, The File Access Operators: To Use, or Not to Use. But within the scope of use filetest 'access';, these tests consider not only the mode bits, but any ACLs (Access Control Lists) that may be applied to the file -- at least, under POSIX systems. Under systems that do not implement access(), this sub-pragma does nothing.

Taking ACLs into account sounds like a Good Thing, but it comes at a price. Within the scope of the 'access' sub-pragma:

Entering the Charts

As part of HalleLeipzig.pm I had my duties to co-organize the recent German Perl Workshop but also the opportunity to give some talks. (Recordings are online [EDIT] now at the CCC video platform). My main talk was about plotting data with Perl (english slides).

Memory Leak in Perl

After a very long time, I found time to blog and here is my journey to deal with memory leak in Perl.

https://theweeklychallenge.org/blog/memory-leak/

Perl Weekly Challenge 173: Sylvester's Sequence in dc

This blog is an answer to the second task of the Week 173 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Originally, the Perl Weekly Challenge called for solutions in Perl and Raku (also known as Perl 6 at the time). But, very soon, people started to provide solutions in other “guest” languages. See for example my blog post providing solutions to the Sylvester’s Sequence task described below in about 15 different guest languages.

One of the languages I tried is dc, and it turned out to be much more difficult and challenging than I initially thought. I actually spent far more time on it than I would wish to admit, at least 5 to 6 hours (not counting the time to write this blog post). One of the problems is that there is only very limited documentation on this old programming language. So I thought it might be useful to describe in some details how I solved it.

The Task

Reconsidering the licensing of Perl code

The current state: The Perl interpreter and most of CPAN are provided under the Artistic 1.0 license and the GPL1.0 license. The Artistic 1.0 license was written by Larry Wall and due to its problems Perl is simultaneously licensed under the GPL 1.0 License.

It is the de-facto standard to license software published to CPAN under the same terms as the Perl interpreter.

The Artistic 2.0 license supersedes the Artistic 1.0 license and is designed to overcome its problems. Raku uses this license as it was specifically created for Perl 6. Mojolicious also uses this license.

The Artistic licenses are not widely used outside the Perl & Raku sphere.

What is the "best" license? (Discussion)

The major philosophical axis in (free) Open Source licenses is Copyleft versus Permissive

"Copyleft" licenses require source code to be made available with compiled software that is distributed. "Permissive" licenses don't have that requirement.

Looking for a new owner for my modules

I'm looking for someone to take over as maintainer of these distributions. Some of these distributions contain relatively important modules, like Redis and IO-Socket-Timeout.

  • Action-Retry
  • Bloomd-Client
  • Bot-BasicBot-Pluggable-Module-RT
  • Dancer-Plugin-FlashMessage
  • Dancer-Plugin-Params-Normalization
  • Exception-Stringy
  • IO-Socket-Timeout
  • Log-Message-Structured-Stringify-AsSereal
  • Moo-Lax
  • POE-Wheel-GnuPG
  • Params-Check-Faster
  • PerlIO-via-Timeout
  • Redis
  • Riak-Client
  • Sereal-Splitter

If you're interested by some or all of them, let me know!

The File Access Operators: To Use, or Not to Use

The file access operators are, for the purpose of this blog entry, the file test operators -r, -w, -x, -R, -W, and -X. The upper case operators test the ability of the user's real UID to read, write, or execute the file being tested. The lower case operators do the same for the user's effective UID.

Though Perl provides these, their documentation comes with cautions about their use. The rest of this blog entry represents my thoughts on their use or avoidance.

Perl Weekly Challenge 173: Esthetic Number and Sylvester's Sequence

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

Spoiler Alert: This weekly challenge deadline is due in a few of days from now (on July 17, 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: Esthetic Number

You are given a positive integer, $n.

Write a script to find out if the given number is Esthetic Number.

An esthetic number is a positive integer where every adjacent digit differs from its neighbour by 1.

For example,

5456 is an esthetic number as |5 - 4| = |4 - 5| = |5 - 6| = 1
120 is not an esthetic numner as |1 - 2| != |2 - 0| != 1

Esthetic Number in Raku

Enlarging the Perlosphere

Although they may be an anthema to many, there are many active Perl communities on Facebook. The primary ones I subscribe to are

Perl Programmers

The Perl Community

The Weekly Challenge

The Perl and Raku Conference

Perl Mongers

If you search for Perl groups, you'll find many, many more, including ones for individual Perl Mongers groups.

If someone wants to talk Perl, I don't care where it is - let's talk.

Replay/Debug/Test Cron Events With Cron::Sequencer

Cross-posted from my own blog: Replay/Debug/Test Cron Events With Cron::Sequencer.

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.