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'
}

Perl Weekly Challenge 217: Sorted Matrix and Max Number

These are some answers to the Week 217 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 May 21, 2023 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: Sorted Matrix

You are given a n x n matrix where n >= 2.

Write a script to find 3rd smallest element in the sorted matrix.

Example 1

Input: @matrix = ([3, 1, 2], [5, 2, 4], [0, 1, 3])
Output: 1

The sorted list of the given matrix: 0, 1, 1, 2, 2, 3, 3, 4, 5.
The 3rd smallest of the sorted list is 1.

Example 2

MooseX::Extended Tutorial

There's been a lot of work on MooseX::Extended and now it comes with a fairly extensive tutorial.

The basics are pretty easy to learn, but it gives you a good amount of power. It also allows you to easily define custom versions so you can just slap use My::Custom::Moose; (or role) at the top or your code and it works just fine.

You can now disable just about any features in it you don't want. You can also include experimental features, such as multimethods (based on number of args) and async/await.

Check out the github repo if you'd like to contribute.

Perl IDE Hackathon 2022

perl ide hackathon.png

On Tuesday 21st June there will be a Perl IDE Hackathon in the Hackathon room at The Perl and Raku Conference. You can also participate in this event remotely.

Our goal is to enhance IDE and Editor support for Perl 5 which is typically via plugins, with an an emphasis on helping people make their first every contribution. It's not even required that you use the IDE/Editor that you are helping out with.

With support from their authors, I am hoping we can help make meaningful contributions to the following, :

- Jetbrains IDEA plugin
- Language Server's for VSCode etc. i.e. Perl Navigator, Perl::LanguageServer, PLS
- Vim plugin vim-perl
- Emacs
- Others!

Recall that IDE support is a priority for the community and we need your help!

If you are attending the Perl and Raku conference then simply turn up at the venue on the 21st with your Laptop and find the room! There will be wifi and we will work together with everyone in the slack channel.

Annotated Perl::Critic Policy Index

In the wake of my postings on the file access tests (-r and friends) I wondered if there was a Perl::Critic policy to find them. So I constructed an annotated index of Perl Critic policies. Because of its size I stuck it on GitHub rather than in-line to this blog post.

This index assumes that any CPAN module whose name begins with Perl::Critic::Policy:: is a Perl Critic Policy. The index entry for each module contains the name of the module itself (linked to Meta::CPAN), the name of the distribution which contains it, and the abstract for the module if it contains anything other than a repeat of the module name. I suppose the module description could have been added, but I hoped the abstract would be sufficient.

This operation gave me 341 policies. I did not find the policy I wanted among them. In fact, only Kevin Ryde's Perl::Critic::Policy::ValuesAndExpressions::ProhibitFiletest_f came close.

For those who want context, the relevant blog posts are:

Perl Weekly Challenge 216: Registration Number

These are some answers to the Week 216 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 May 14, 2023 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: Registration Number

You are given a list of words and a random registration number.

Write a script to find all the words in the given list that has every letter in the given registration number.

Example 1

Input: @words = ('abc', 'abcd', 'bcd'), $reg = 'AB1 2CD'
Output: ('abcd')

The only word that matches every alphabets in the given registration number is 'abcd'.

Example 2

Input: @words = ('job', 'james', 'bjorg'), $reg = '007 JB'
Output: ('job', 'bjorg')

Strawberry Perl

Do you want to convert Perl source into .exe?

Please checkout my experience.

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

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).

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.

Perl Weekly Challenge 215: Odd One Out and Number Placement

These are some answers to the Week 215 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 May 7, 2023 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: Odd One Out

You are given a list of words (alphabetic characters only) of same size.

Write a script to remove all words not sorted alphabetically and print the number of words in the list that are not alphabetically sorted.

Example 1

Input: @words = ('abc', 'xyz', 'tsu')
Output: 1

The words 'abc' and 'xyz' are sorted and can't be removed.
The word 'tsu' is not sorted and hence can be removed.

Example 2

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.

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.

Perl Weekly Challenge 213: Fun Sort

These are some answers to the Week 213 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 April 23, 2023 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: Fun Sort

You are given a list of positive integers.

Write a script to sort the all even integers first then all odds in ascending order.

Example 1

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

Example 2

Input: @list = (1,2)
Output: (2,1)

Example 3

Input: @list = (1)
Output: (1)

Fun Sort in Raku

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

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

Introducing MooseX::Extended

MooseX::Extended is coming along well and is ready for testing. See Introducing MooseX::Extended for a decent introduction on how to make writing your Moose code safer and easier.

What happened to Perl 7?

With Perl 5.36.0 just around the corner, we thought that this is a good time to clarify plans for the future of the Perl programming language. We realised that the future was hammered out in a number of steps, across several months. This meant that there hasn't been a single statement we could refer people to. This post is to fill that gap.

Perl Weekly Challenge 212: Rearrange Groups

These are some answers to the Week 212 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 April 16, 2023 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: Jumping Letters

You are given a word having alphabetic characters only, and a list of positive integers of the same length.

Write a script to print the new word generated after jumping forward each letter in the given word by the integer in the list. The given list would have exactly the number as the total alphabets in the given word.

Example 1

Do you want to get started with Perl v5.36?

Let us all have fun with the latest Perl v5.36.

https://theweeklychallenge.org/blog/get-started-with-perl-v536

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:

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.