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.
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'
}
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on July 2, 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: Count Primes
You are given a positive integer, $n.
Write a script to find the total count of primes less than or equal to the given integer.
Example 1
Input: $n = 10
Output: 4
Since there are 4 primes (2,3,5,7) less than or equal to 10.
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.
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.
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!
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on June 25, 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: Matching Members
You are given a list of positive integers, @ints.
Write a script to find the total matching members after sorting the list increasing order.
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!
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.
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.
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.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on June 18, 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.
Arithmetic Subsequence
You are given an array of integers, @ints.
Write a script to find the length of the longest Arithmetic Subsequence in the given array.
A subsequence is an array that can be derived from another array by deleting some or none elements without changing the order of the remaining elements.
A subsequence is arithmetic if ints[i + 1] - ints[i] are all the same value (for 0 <= i < ints.length - 1).
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
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on June 18, 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.
Good Strings
You are given a list of @words and a string $chars.
A string is good if it can be formed by characters from $chars, each character can be used only once.
Write a script to return the sum of lengths of all good strings in words.
Example 1
Input: @words = ("cat", "bt", "hat", "tree")
$chars = "atach"
Output: 6`
The good strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.
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.
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, :
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.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on June 11, 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.
Squareful Arrays
You are given an array of integers, @ints.
An array is squareful if the sum of every pair of adjacent elements is a perfect square.
Write a script to find all the permutations of the given array that are squareful.
Example 1:
Input: @ints = (1, 17, 8)
Output: (1, 8, 17), (17, 8, 1)
(1, 8, 17) since 1 + 8 => 9, a perfect square and also 8 + 17 => 25 is perfect square too.
(17, 8, 1) since 17 + 8 => 25, a perfect square and also 8 + 1 => 9 is perfect square too.
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.