Perl Weekly Challenge 182: Unique Array and Date Difference

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

Task 1: Unique Array

You are given list of arrayrefs.

Write a script to remove the duplicate arrayrefs from the given list.

Example 1

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

Example 2

Input: @list = ([9,1], [3,7], [2,5], [2,5])
Output: ([9, 1], [3,7], [2,5])

Unique Array in Raku

The Raku solution is essentially a one-liner (more than one line because of the tests). We convert the sub-arrays into strings and use the unique built-in routine to remove duplicates.

My Favorite Warnings: deprecated

The deprecated warning is a grab-bag. Basically, anything that is deprecated causes this warning to be generated, and the list changes from release to release.

The only reason I can think of ever to turn this off is around a deprecated construction while you are actively working to eliminate it. Silencing it and then forgetting about it will bite you, eventually.

For the curious (and to run my word count, since otherwise this would be a really short blog entry), the current list of deprecations according to the 5.34.0 perldiag is:

Reviving Net::Pcap

I've blogged a bit about my steps to get Net::Pcap to compile again - I won't paste the complete text here unless there is demand, but I'm posting the link to the article here :)

https://corion.net/blog/2021/10/26/reviving-net-pcap/

Some Perl Code In Memory of a Great Scientist

On August 21, 2021, famous Polish mathematician Andrzej Schinzel passed away at the age of 84. He was one of the great minds behind modern number theory. May he rest in peace. I have extended one of my CPAN modules relating to his work and dedicated the release to his memory.

Perl Weekly Challenge 182: Max Index and Common Path

These are some answers to the Week 182 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 Sept. 18, 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: Max Index

You are given a list of integers.

Write a script to find the index of the first biggest number in the list.

Example:

Input: @n = (5, 2, 9, 1, 7, 6)
Output: 2 (as 3rd element in the list is the biggest number)

Input: @n = (4, 2, 3, 1, 5, 0)
Output: 4 (as 5th element in the list is the biggest number)

Max Index in Raku

My Favorite Modules: diagnostics

One of the things the Perl 5 Porters work hard on is issuing diagnostics that are actually diagnostic. I think they do a pretty good job at this, but sometimes I need a bit more explanation than the typical one-line message.

Now, there is documentation on all of these in perldiag, but paging through that looking for my message is a pain.

Fortunately, there is a module for that: diagnostics. This module causes diagnostics to be expanded into their full explanation as it appears in perldiag.

Typically you would not put a use diagnostics; in your Perl code, though of course you could. Instead, you would load it via a command-line option to perl, or maybe via environment variable PERL5OPT. That is, either

$ perl -Mdiagnostics my-flaky-perl.PL

or

$ env PERL5OPT=-Mdiagnostics perl my-flaky-perl.PL

I try match syntax using Syntax::Keyword::Match


Syntax::Keyword::Match is a module to enable match syntax in the current Perl by Paul Evans who is one of the current Perl Steering Councils. See perlgov about the Perl Steering Council.

Syntax::Keyword::Match Examples

Syntax::Keyword::Match Examples

Number matching

Number matching. Match syntax is similar as a switch syntax of C language.

Monthly Report - September

Finally enjoying again ...

The month of September is very special to me personaly.

Why?

Well, I got married in the very same month 18 years ago. The best part is, I choose the day 11 to get married. I have never missed my wedding anniversary, thanks to all the TV news channel.

How?

On the day, every year I find every TV news channel talk about 9/11 episode. It works like reminder to me.

Let's get back to the main topic ...

For the last few months, I have been late in making monthly report on time. This has created many problems for me. One of them and the most important is that I don't remember what I did last month. I then look back my activities on various social platforms that I am active on e.g. Facebook, Twitter and LinkedIn. It doesn't always help as I am not very active either socially these days.

BTW, I started working on this report around 6 am today.

So what's going on?

Perl Weekly Challenge 181: Sentence Order and Hot day

These are some answers to the Week 181 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 Sept. 11, 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: Sentence Order

You are given a paragraph.

Write a script to order each sentence alphanumerically and print the whole paragraph.

Example:

My Favorite Warnings: uninitialized

This warning was touched on in A Belated Introduction, but I thought it deserved its own entry.

When a Perl scalar comes into being, be it an actual scalar variable or an array or hash entry, its value is undef. Now, the results of operating on an undef value are perfectly well-defined: in a nuneric context it is 0, in a string context it is '', and in a Boolean context it is false.

The thing is, if you actually operate on such a value, did you mean to do it, or did you forget to initialize something, or initialize the wrong thing, or operate on the wrong thing? Because of the latter possibilities Perl will warn about such operations if the uninitialized warning is enabled.

If you really intended to do this, no warnings 'uninitialized'; will suppress the error.

Web::PageMeta - a mixed sync/async lazy Perl Moose HTTP-GET module

Announcing here Web::PageMeta which is lazy build-ed HTTP-GET and web-scrape-data module able to work both in classic code and also to behave non-blocking in async code. More info on my blog or on CPAN or on GitHub .

Latest Perl Introduction 2021 Movie

Perl version 5.36. isa operator. try catch syntax. enable warnings. use v5.36. use v7. The introduction of the members of Perl core team.

Perl Weekly Challenge 180: First Unique Character and Trim List

These are some answers to the Week 180 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 Sept. 4, 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: First Unique Character

You are given a string, $s.

Write a script to find out the first unique character in the given string and print its index (0-based).

Example 1

Input: $s = "Perl Weekly Challenge"
Output: 0 as 'P' is the first unique character

Example 2

Input: $s = "Long Live Perl"
Output: 1 as 'o' is the first unique character

First Unique Character in Raku

My Favorite Modules: if

My blog post My Favorite Warnings: redundant and missing touched on the use of the if module. Comments on that post made me think it deserved a top-level treatment, expanding on (though not necessarily improving on) Aristotle's comment.

The if module is a way to conditionally load another module and call its import() or unimport() method. Sample usages are

use if CONDITION, MODULE, ...; # load and import
no if CONDITION, MODULE, ...;  # load and unimport

In actual use the CONDITION is an expression that is evaluated at compile time. If that expression is true the named module will be loaded and its import() or unimport() method called with whatever arguments were specified. If the condition is false, nothing is done. If MODULE is a string literal it will have to be quoted, since as far as Perl is concerned it is just another argument.

Util::H2O ~ Iterative Refinement of Existing Perl Code

Util::H2O is an incredibly powerful tool for managing HASH references in a more natural way.

This post is the first of several that will explore this awesome module. I've started using it quite a bit in both new code and in existing code. There are several imporant cases where it really shines. Here we explore the power it has to iteratively refine existing code. It's also fun and easy to introduce into existing code.

Util::H2O provides a method called h2o that provides a very powerful way for turning a hash reference to an object . Generally speaking, this means I get accessors with as few keystrokes as possible.

I've been using this module quite a bit recently, and I really do like the improvements it has over the more traditional modules used for generating accessors.

The most basic use of h2o is to provide accessors to a hash reference with a single level of keys. I tend to use hash references a lot .

SPVM 0.9014 Release - add class, method, static keyword, omit SPVM:: namespace

I release SPVM 0.9014. Latest releases have some big changes.

add class, method, static keyword, omit SPVM:: namespace, and remove sub, self, keyword.

Before

Perl Weekly Challenge 179: Ordinal Numbers and Unicode Sparkline

These are some answers to the Week 179 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. 28, 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: Ordinal Number Spelling

You are given a positive number, $n.

Write a script to spell the ordinal number.

For example,

11 => eleventh
62 => sixty-second
99 => ninety-ninth

Hum, this task is not very interesting, since it has more to do with English than with computer science. I’m not going to enumerate dozens of numeral or ordinal English names. So, contrary to what I usually do, I’ll use an off-the-shelf module to complete this task.

Ordinal Number Spelling in Raku

My Favorite Modules: Term::ReadLine::Perl

Term::ReadLine is a core module (since Perl 5.002) that provides an extremely limited text interface of the prompt-and-type variety. Its main virtue is that you can add a back end which gives it things like command history, editing, and completion.

The back ends live in the Term::ReadLine::* name space, and you can control which one you get by defining the PERL_RL environment variable as documented at Term::ReadLine. If this is not defined, various undocumented things are tried; if none works you get the bundled minimal interface, Term::ReadLine::Stub.

The preferred back end (at least, according to Bundle::CPAN as of this writing) is Term::ReadLine::Perl. This is a shy, retiring module, with no POD documentation at all, which provides readline-style history, editing, and completion. By default the only completion you get is file name completion, but with some work you can expand this to do whatever you can figure out.

At this point, some words of caution are probably in order.

Monthly Report - August

Finally enjoying again ...

Ever since I joined Oleeo, I keep talking about it in every monthly report.

Why?

Well, right from day one, I have been getting to work on something I never worked on before. To be honest with you, I was expecting to fight with good old CGI ridden code mostly. I find myself lucky to have such a great supporting team. Right now I am playing with Elastic Search and I am enjoying it. Thanks to CPAN for such a cool library, Search::Elasticsearch.

Did you notice last monthly report was published on 22nd Aug?

I have never been so late ever since I started the series of monthly report.

You must be thinking, why bother with monthly report? Who cares what I do?

I agree, nobody cares. But I still do it every month since Nov 2018, my first monthly report was published on 2nd Nov 2018. In two months time, I would complete 3 years of monthly reporting. Honestly speaking, I didn't realise it until now.

How to show UTF-8 at the Windows command prompt

If you windows Perl user, It is good to know How to show UTF-8 at the Windows command prompt .

How to show UTF-8 at the Windows command prompt

One liner is yet buggy, however UTF-8 showing is good in Windows command prompt.

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.