Perl Weekly Challenge 225: Left Right Sum Diff

These are some answers to the Week 225, Task 2, 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 July 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 2: Left Right Sum Diff

You are given an array of integers, @ints.

Write a script to return left right sum diff array as shown below:

The progress of the new class feature of Perl

I introduce the progress of the new class feature of Perl. If you are interested in the progress of the new class feature of Perl, please see the following topics.

p5p Mailing List

Pre-PR Preview of `use feature 'class'`

Trial of the implementation

leonerd/perl5/feature-class | Github

Specification

Corinna RFC

In the current spec, the new class syntax is the following codes.

Death: A Terminal Experience

A program being executed, self terminating on encountering an non-viable condition is a typical scenario in Perl programs. The death sentence can deliver information about the departed application to the user as justification and demand appropriate resolution for the subsequent reincarnation.

Now I know my code fails more often than it succeeds, and it is for this reason I am planning an alternative wake for the programmed parting of my future terminal applications. As a once-in-a-run-time event, death might be more elaborately delivered, something to be celebrated. The last words of a dying application softens the developers ensuing grief, while encouraging resuscitation with an appropriately delivered injection of code.

Imagine my code being transformed from:-

do_something_risky() or die "you evil monster $!";

into

get_away_with_it() or deathSentence($!) 

producing something like this on the terminal:-

death.png

I know such distraction wastes time, there are probably many more error trapping and diagnostic tools available. These may be absorbed over time...I am not really an expert. But I am collecting a series of reasonably uncontroversial, hopefully humorous "epitaphs"...

On interpolating stuff into pattern matches

Tom Wyant:

Interestingly (to me, at least) they reported that the removal of the /o modifier made their case 2-3 times slower. This surprised me somewhat, as I had understood that modern Perls (for some value of "modern") had done things to minimize the performance difference between the presence and absence of /o.

They indeed have.

Ironically, it’s qr objects which don’t get that benefit. On the machine I’m typing on, the following benchmark…

Perl Weekly Challenge 225: Max Words

These are some answers to the Week 225, Task 1, 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 July 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: Max Words

You are given a list of sentences, @list.

A sentence is a list of words that are separated by a single space with no leading or trailing spaces.

Write a script to find out the maximum number of words that appear in a single sentence.

Example 1

Input: @list = ("Perl and Raku belong to the same family.",
                "I love Perl.",
                "The Perl and Raku Conference.")
Output: 8

Example 2

Match Anything, Quickly -- Revision 1

O wad some Power the giftie gie us
To see oursels as ithers see us!
It wad frae mony a blunder free us,
An' foolish notion: ...

My previous blog post, Match Anything, Quickly, brought a number of responses which are worth reading in their own right. The one that triggered this post, though, was from Nerdvana and Devin of Cincinnati Perl Mongers, who pointed out an error in my benchmark script. I had left off the intended /smx from the qr/ ... / version of the test, which meant that the regular expression did not in fact match.

Three cheers for code reviews!

The Cincinnati Perl Mongers came up with a further case which combines my two:

eval "do { my \$regex = qr/ $re /smx; " .
        "sub { \$MATCH =~ /\$regex/o }};"

They benchmarked this as being slightly slower than the case where the regular expression is simply interpolated into the subroutine verbatim.

Introducing Venus, a new world for Perl 5

Abstract

Programming in Perl is choices all the way down. Perl is a multi-paradigm programming language which means that Perl can support the development of software using different programming paradigms, e.g. functional programming, object-oriented programming, and more.

Programming languages are culture, and culture follows philosophy. Philosophy is how every culture provides itself with justification for its decisions, values, beliefs, and worldview.

Perl's philosophy

Perl's philosophy is TIMTOWTDI, i.e. “there’s more than one way to do it”. You might even say that Perl takes the position of not taking a position, and this disposition applies to the topic of a standard library as well.

To be clear, what some will call Perl's standard library is little more than a grab bag of functions, pragmas, and packages shipped together with the core. This collection is a mix of functional and object-oriented styles and is intentionally lightweight.

It’s probably worth mentioning that the Raku team has also adopted this posture (and tradition).

What if Perl had a standard library?

RFC: new API for Type::Params

Firstly, I'm not planning on breaking compatibility with Type::Params. The new API would live under a different namespace, such as Type::Params2.

The API for Type::Params is currently:

Perl Weekly Challenge 224: Special Notes

These are some answers to the Week 224, Task 1, 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 July 9, 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: Special Notes

You are given two strings, $source and $target.

Write a script to find out if using the characters (only once) from source, a target string can be created.

Example 1

Input: $source = "abc"
       $target = "xyz"
Output: false

Example 2

Input: $source = "scriptinglanguage"
       $target = "perl"
Output: true

Example 3

Please relicense from "Perl 5" to MIT or Apache 2.0 license

Following from my previous post, I am now actively encouraging everyone to switch licenses to MIT/ISC license or Apache 2.0.

My reasoning is that in the vast majority of cases the author and contributors want the software to be used by as many businesses and hobbyists as possible.

Previously I described how the burden of understanding and complying with licenses, including open source licenses, can be an unintended barrier to them using the software.

Perl modules tend to use "Perl 5" combination as the default license i.e. "Licensed under the same terms as Perl itself". And the "Perl 5" license is actually a dual licensing of the problematic Artistic 1.0 license and the dated GPL1.0 license which also has problems. Both are rarely used outside of Perl and in my view present a barrier to adoption.

Recall I described how permissive ("BSD") and copyleft ("GPL") licenses are functionally identical if no binary is distributed (websites) or for scripted languages that remain in source form.

CPM0 frl-plugin:perlscript: ERROR: 'times' trapped by operation mask at /usr/lib64/perl5/B.pm line 183.

Hello ,
When "use DateTime;" library is included in perl file ,getting the error as

"CPM0 frl-plugin:perlscript: ERROR: 'times' trapped by operation mask at /usr/lib64/perl5/B.pm line 183."

Could someone provide some inputs on the same.
Also to which tag does this opcode 'times' belong to ?
example: fork,wait, waitpid will belong to :subprocess

Regards
Kavya

Match Anything, Quickly

Revision: that Cincinnati Perl Mongers found an error in the benchmark script used for this post. Match Anything Quickly - Revision 1 discusses their findings and links to a revised benchmark script. -- TRW 2022-09-02

Sometimes I want to filter a set of strings, but the details of the filter are not known beforehand. In particular, I may want a null filter, which simply accepts anything.

This looks like a job for a regular expression, but I can think of at least two implementations. One is to pass around regular expression objects. The second is to wrap a match (m//) in a subroutine reference, and pass that around. Given the use of regular expressions, there are a number of possibilities for a regular expression that matches any string.

Perl Weekly Challenge 223: Box Coins

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

Task 2: Box Coins

You are given an array representing box coins, @box.

Write a script to collect the maximum coins until you took out all boxes. If we pick box[i] then we collect the coins $box[i-1] * $box[i] * $box[i+1]. If $box[i+1] or $box[i-1] is out of bound then treat it as 1 coin.

Example 1:

Input: @box = (3, 1, 5, 8)
Output: 167

Step 1: pick box [i=1] and collected coins 3 * 1 * 5 => 15.  Boxes available (3, 5, 8).
Step 2: pick box [i=1] and collected coins 3 * 5 * 8 => 120. Boxes available (3, 8).
Step 3: pick box [i=0] and collected coins 1 * 3 * 8 => 24.  Boxes available (8).
Step 4: pick box [i=0] and collected coins 1 * 8 * 1 => 8.   No more box available.

Example 2:

SPVM continues to undergo heavy changes.

Sorry, SPVM continues to undergo heavy changes.

After building real-world modules and applications, I realized that a lot of changes needed to be made.

You can see what I'm currently working on below.

SPVM modules - CPAN modules

JSON - JSON

Math - Math functions

Regex - Regular Expression

Unicode - Unicode Utilities

Base64 - Base 64

Time::Local - Time Reverse Manipulation

SPVM::Errno - Error Number

SPVM::Resource::Re2::V2022_06_01 - Resource of Google RE2 release 2022-06-01.

SPVM::Resource::Zlib::V1_2_11 - zlib v1.2.11 Resource

SPVM::Cwd - get pathname of current working directory

SPVM::IO - File IO, Socket, Select/Polling.

SPVM::Digest::MD5 - SPVM interface to the MD5 Algorithm

SPVM::Digest::SHA - SPVM extension for SHA-1/224/256/384/512

Integrated Inconsistencies.

I will get it wrong. I will start off by saying that, not just because I am married and this sentiment has been conjugally programmed in me for years, but because doing things "my way" will not suit everybody. We approach life, programming, drawing from different perspectives, different analogies, and one method however disagreeable to one person, may be perfectly logical to another. Even our own actions and analysis show conflicts. Take a cup of tea. I drink from the top of the cup, but measure from the bottom. Take character position in programming code...we measure lines from the top, then character on that line. But when we write, we write one line at a time, populating columns in a line before going to the next line.

The Perl Advent Calendar 2022 Call for Papers is Now Open

In the year 2000, the world was a different place. Y2K was still fresh in our memories, many of us had just partied like it was 1999 and Mark Fowler had given up eating chocolate.

Read the full article.

Perl Weekly Challenge 222: Matching Members and Last Member

These are some answers to the Week 222 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 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.

Example 1

Numeric Variable Names With Leading Zeroes

Over on the p5p mailing list, a user raised the issue that use of variable $00 is an error starting with Perl 5.32, and asked that this "regression" be fixed.

I have always understood that variables whose names begin with anything but an alphabetic or an underscore are reserved to Perl, and you mess with them at your peril. And this is the gist of the Porters' response to the post. Recent versions of perlvar say this explicitly, though earlier versions of that document restrict themselves to describing currently-implemented special variables.

For what it's worth, perl532delta appears not to mention this as a new diagnostic.

I wondered how much of this kind of thing was in CPAN, so I whipped up a Perl::Critic policy to try to find them: Variables::ProhibitNumericNamesWithLeadingZero. I then ran this against CPAN as it stood July 23 2022.

Climbing the Charts (request for feature requests)

Hurray, released another version of Chart without new features. Actually rewrote the complete documentation and I guess especially this page (with a little help of this list) is all what most people need. That also allowed us to drop the old PDF and HTML docs which took 8/9 of the distributions space (good side effect).

But main reason to tell this: writing the docs forced me to plough through most of code and also test most of it with self written or at least adapted code, which brought me into the position actually understand what I maintain.

So now I can give actually intelligent responses to feature requests. So please post them here or there. And yes , there will be SVG support, but not soon.

Ideas from TPRC2022: Bug/Task/Issue independent interface and a cli tool

We have a Database Independent Interface aka DBI and a Unified Cache Handling Interface aka CHI which both provide a generalized interface to similar backend services. Similarly we have AnyEvent - the DBI of event loop programming and Log::Any. With the Nopaste cli provides an agnostic tool to send data to pastebin like services.

So why not a generalized interface to Bug, Task, and Issue trackers? And an accompanying cli tool?

Jira is obviously very common for organizations to use, Github issues are ubiquitous, Bugzilla is still around, Request Tracker has a strong following, not to mention Zendesk, OTRS, and so many others you're forced to use each day for your work. Likely your organization or employer uses more than one!

Having a generalized interface makes automation interactions more trivial and vastly more consistent. With this interface established, an accompanying command line tool becomes a logical addition. And if you aren't yet automating interactions with your Bug / Task / Issue tracker, then having an interface is even more important to getting you started.

Such an interface would be the majority of whats needed for a unified interface and cli tool and to interact with CPAN modules bugs/issues regardless if they are on Github, RT, or other. Something similar to Debian's reportbug command.

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.