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 176: Permuted Multiples and Reversible Numbers

These are some answers to the Week 176 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 Aug. 7, 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: Permuted Multiples

Write a script to find the smallest positive integer x such that x, 2x, 3x, 4x, 5x and 6x are permuted multiples of each other.

For example, the integers 125874 and 251748 are permuted multiples of each other as

251784 = 2 x 125874

and also both have the same digits but in different order.

Output

142857

ERROR: 'flock' trapped by operation mask at /usr/lib64/perl5/vendor_perl/Storable.pm

Hello All,
Facing flock error when trying to execute the Automated unit testing .

705:041754.467 CPM0 frl-plugin:perlscript: ERROR: 'flock' trapped by operation mask at /usr/lib64/perl5/vendor_perl/Storable.pm line 268.
Compilation failed in require at /usr/share/perl5/vendor_perl/Const/Fast.pm line 15.
Compilation failed in require.
BEGIN failed--compilation aborted.

Could anyone please help on the issue

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.

German Perl/Raku Workshop recordings are online

During the last days, we reviewed and cut the video recordings. The recordings
are now available on the media platform of the CCC:

https://media.ccc.de/c/gpw2022

Some of the presentations are not yet published - we need to work on
the video some more..

Again, thanks to our speakers, our sponsors and everybody else for the
great conference. Next year we'll hopefully meet again in 2023 in Frankfurt am Main in person!

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:

Introduction Test::Excel

Test::Excel now supports regex, for more information, please follow the link.

https://theweeklychallenge.org/blog/test-excel

Mite: an OO compiler for Perl

Moose is great, but it does introduce a slight performance hit to your code. In the more than 15 years since it was first released, hardware improvements have made this less of a problem than it once was. Even so, if performance is a concern for your project, Moose might not be what you want. It also has a fairly big collection of non-core dependencies.

Moo is a lighter weight version, minus with meta-object protocol, but supporting nearly all of Moose's other features. It loads faster, sometimes runs faster, and has fewer dependencies. (And most of the dependencies it does have are just modules which used to be part of Moo but were split out into separate distributions.)

But what if you could have fast Moose-like object-oriented code without the dependencies?

In 2013, Michael Schwern started work on Mite to do just that. It was abandoned in 2014, but I've taken it over and expanded the feature set to roughly equivalent to Moo.

Mite is an object-oriented programming compiler for Perl. It allows you to write familiar Moose-like object-oriented code, then compile that into plain Perl with zero non-core dependencies. Your compiled code does not even have a dependency on Mite itself!

We have a new Perl Steering Council for 2022/23

Following the release of 5.36.0, we have a new Perl Steering Council (PSC). The PSC for the next year comprises Ricardo Signes (RJBS), Paul Evans (PEVANS), and Philippe Bruhat (BOOK). These three will serve until 5.38.0 is released, at which point the next PSC will be elected.

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.

Smart Match in CPAN

There is nothing like looking, if you want to find something. -- The Hobbit, iv, "Over Hill and Under Hill"

Recently on the p5p mailing list the topic of removing smart match re-surfaced. There was a fairly vigorous discussion about the effect this would have on CPAN. So I thought I would look into how many uses there actually were.

Fortunately there are Perl Critic policies for this: Jan Holčapek's Perl::Critic::Policy::ControlStructures::ProhibitSwitchStatements and Perl::Critic::Policy::Operators::ProhibitSmartmatch. All I had to do was run them against my mini-CPAN.

My results:

  • Total distributions: 40704
  • Distributions with violations: 842
  • Files with violations: 1568

A look at the file names involved says that about two-thirds of the violations are in the published modules themselves, and the rest are in support code (directories t/, inc/, and the like).

It is possible that the results of Perl::Critic::Policy::ControlStructures::ProhibitSwitchStatements contain false positives simply because someone implemented subroutines named given() or when() unrelated to smart matching.

Trying to contact Francis van Dun (FVANDUN)

I am trying to contact Francis van Dun (FVANDUN on cpan) for permission to relicense Net::DHCP to the MIT license.

The email listed on cpan bounces. If you are out there Francis please give me your blessing via the above link.

Decode Hexdump

Please checkout my experience decoding hexdump.

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

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

My Favorite Modules: File::stat

File::stat overrides the core stat() and lstat() functions. Instead of arrays, the new functions return an object having methods corresponding to the elements of the arrays returned by the original functions. This module has been in core since Perl 5.004.

The advantage of this module is clearer code. For example, to get the size of file $file without it is something like

    my $size = ( stat $file )[7];

But with this module the same effect is given by

    my $size = stat( $file )->size();

Once you have the object in hand, you cam query it for any of its properties, so if you want both size and modification time, instead of

    my ( $size, $mtime ) = ( stat $file )[ 7, 9 ];

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.

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

Announcing perlcritic Policy ValuesAndExpressions::ProhibitFiletest_rwxRWX

Since several places in the Perl documentation caution against the use of the file access operators (-r and friends), and since I was unable to find a Perl::Critic policy dealing with this, I thought I would make one: Perl::Critic::Policy::ValuesAndExpressions::ProhibitFiletest_rwxRWX.

This policy is assigned to the 'bugs' theme. It has low severity because there are some uses of these operators that seem legitimate to me -- or at least I see no easy way to get around their use.

On the one hand, something like

-r $file or die "File $file not readable\n";
open my $handle, '<', $file;

is wrong several ways. On the other hand, it is hard to see how to implement File::Which without the use of -x. And in fact it does use -x.

Do you have Perl question?

Here is my response ...

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

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.