Perl Weekly Challenge 208: Minimum Index Sum and Duplicate and Missing

These are some answers to the Week 208 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 March 19, 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: Minimum Index Sum

You are given two arrays of strings.

Write a script to find out all common strings in the given two arrays with minimum index sum. If no common strings found returns an empty list.

Example 1:

Installing Perl: A Chicken-and-Egg Problem

A couple days ago the SD card on a Raspberry Pi lost its beady little mind, and I ended up rebuilding the system from scratch. I generally build my own Perl (also from scratch) and then install the modules I need. So that I can have a log file to rummage through in the event of a problem, I start by configuring the CPAN client interactively, and then doing

$ cpan YAML 2>&1 | tee YAML.log
$ cpan Bundle::CPAN 2>&1 | tee YAML.log

Normally I would now install the modules specific to my use. But when I tried this time I got

HTTP::Tiny failed with an internal error: IO::Socket::SSL 1.42 must be installed for https support
Net::SSLeay 1.49 must be installed for https support

Please test DBD::Oracle v1.90_1

Anyone using DBD::Oracle is invited to test out out this dev release v1.90_1

Download from metacpan here

GH Tag here

v1.90 candidate branch

This commit is a big big change which should hopefully fix a lot of problems

Access the Tesla API with Perl!

For several years, I spent much time writing code for the Raspberry Pi, including hardware level register C code so that we can use various Integrated Circuit chips and sensors with Perl.

A couple of years ago, I acquired much larger and much more expensive toy, an all-wheel drive, full auto-pilot Tesla Model-X SUV, so of course, I want to write Perl code to access and manipulate it.

In the ensuing two years, I developed several microcontroller-based devices for the car, including one that knows where the car is, and its battery charge and state, and dispslays this information via an LED light strip and an OLED screen inside of my garage, along with an audible alarm that sounds for 1/8th of a second every three seconds if the battery is below a certain threshold so I don't forget to plug the charger in.

Perl Weekly Challenge 207: Keyboard Word and H-Index

These are some answers to the Week 207 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 March 12, 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: Keyboard Word

You are given an array of words.

Write a script to print all the words in the given array that can be types using alphabet on only one row of the keyboard.

Let us assume the keys are arranged as below:

Row 1: qwertyuiop
Row 2: asdfghjkl
Row 3: zxcvbnm

Example 1

Input: @words = ("Hello","Alaska","Dad","Peace")
Output: ("Alaska","Dad")

Example 2

Dancer2 0.400000 Released

Dancer2 0.400000 has been released, and is on its way to CPAN.

We realize that some of you might be curious as to the large version bump. There are a couple of reasons for this: - Modules we depend on bumped their minimum Perl version to 5.12, requiring us to follow suit. - As of 2022, Dancer2 has an official deprecation policy. We are implementing this policy effective with this release, and it will help shape and guide future development. - We’ve officially marked a lot of outdated and unused API as being deprecated.

With that, the following APIs, methods, etc. are now officially deprecated:

  • Dancer2::Test
  • request->dispatch_path
  • push_header
  • header
  • headers
  • context
  • Named placeholders: splat and capture

In plugins:

  • plugin_setting
  • dancer_app
  • request
  • var
  • hook

To discuss any of these, you can find issue for each of the above here.

TWC 155: I say Potato, you say Pisano

In which we reach the first plateau of clever, then (unfortunately) stop climbing.

(Still editing)

XS versus clang: Infinite warnings

Around the beginning of 2022 I started noticing a large number of warnings when compiling XS modules under macOS 12 Monterey. These looked like warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro], and appeared to originate fairly deeply in Perl's macro stack.

This week I was moved to address them for my one lone XS distribution, Mac-Pasteboard. Not only are they really annoying, but they would make it difficult or impossible to find anything more serious.

A little web searching seemed to say that this warning was added in clang 12.0, and is enabled by default. Beyond that, I did not find much. A Ruby ticket turned up, but the patch involved rewriting the relevant macros so that the warning was not tickled. A desultory check of a few other XS modules that came to mind did not provide any help -- they all showed the same behavior.

Perl Weekly Challenge 206: Shortest Time and Array Pairings

These are some answers to the Week 206 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 March 5, 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: Shortest Time

You are given a list of time points, at least 2, in the 24-hour clock format HH:MM.

Write a script to find out the shortest time in minutes between any two time points.

Example 1

Input: @time = ("00:00", "23:55", "20:00")
Output: 5

Since the difference between "00:00" and "23:55" is the shortest (5 minutes).

Example 2

The benefits of change, from an amateur's objective perspective.

As a bystander in the evolution of Object-Oriented Programming in Perl, and someone who is really only just starting to get the hang of Perl modules and packages (still not any good at it), I get really quite overwhelmed by ideologies. There is considerable debate about the right way to program things, the right style, the right direction that Perl should go. It is Vim vs Emacs, Atari ST vs Amiga, Mods vs Punks. Really one needs a language to do what one needs it to do, simply, quickly and consistently. For an amateur, Perl has been able to do exactly that for me. I code rubbishly, but hey, who's looking?

TWC Episode 154 - Padawan Missing

In which we search for a needle in a lendee
(or maybe a chatchka in a haystack),
and delight in some lazy CPAN comfort.

Cloud Provider Performance Comparison - Perl & more

UPDATE: For the newer (2023) comparison see here.

Last year, impressed with the apparent speed of an M1 Mac Mini I bought to try out, I explored its perl performance and wrote about it in a  blog post . I used mainly my own benchmarks which were mostly representative of workloads I was interested in.

Perl Weekly Challenge 205: Third Highest and Maximum (Bit-Wise) XOR

These are some answers to the Week 205 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 February 26, 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: Third Highest

You are given an array of integers.

Write a script to find out the Third Highest if found otherwise return the maximum.

Example 1

Input: @array = (5,3,4)
Output: 3

First highest is 5. Second highest is 4. Third highest is 3.

Example 2

I start to write the book "Perl for Beginners to Mastering Perl in a week"

I start to write the book "Perl for Beginners to Mastering Perl in a week".

I wrote two Japanese books from a years ago.

Perlテキスト処理のエッセンス

PerlでポータブルなLinuxファイル管理入門

Finally, I decided to write English books.

Recently it becomes easy to publish both e-books and paperbacks.

The title of my first English Perl book is "Perl for Beginners to Mastering Perl in a week".

This book is for Perl beginners to learn Perl quickly.

My Favorite Modules: Devel::NYTProf

'It is a capital mistake to theorize before one has data.' -- Sherlock Holmes, "A Scandal in Bohemia"

The mental excursion that led to this blog post started with a report from Olaf Alders that my Perl::Critic::Policy::Variables::ProhibitUnusedVarsStricter was generating a false positive on variables used only as defaults in subroutine signatures. After the first cut at fixing this I thought a regression test was in order. I did this by running both unpatched and patched versions of the policy against my Mini CPAN, and then diff on the outputs.

This has always taken the better part of a day to run, and given that it had to expand all the distributions first and then run a fairly brute-force policy against anything it found, I accepted this as the price of conscientiousness.

Finding unused variables in your Perl code

I've put together a brief overview of some of the ways to automate finding unused variables in your Perl code:

https://www.olafalders.com/2022/02/22/finding-unused-perl-variables/

Perl Weekly Challenge 204: Monotonic Arrays and Reshape Matrix

These are some answers to the Week 204 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 February 19, 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: Monotonic Array

You are given an array of integers.

Write a script to find out if the given array is Monotonic. Print 1 if it is otherwise 0.

An array is Monotonic if it is either monotone increasing or decreasing.

Monotone increasing: for i <= j , nums[i] <= nums[j]

Monotone decreasing: for i <= j , nums[i] >= nums[j]

Example 1

Input: @nums = (1,2,2,3)
Output: 1

Example 2

Input: @nums (1,3,2)
Output: 0

The progress of the SPVM language 2022

Hi, I write the progress of the SPVM module 2022.

SPVM is a programming language that is build on top of the Perl ecosystem and provides fast calculation and array operation to Perl.

SPVM can be transpiled to C language, and it can be compiled to shared libraries and executable files.

SPVM can call C/C++/Cuda libraries by writing pure C/C++/Cuda language without XS.

I wrote SPVM from 2016. I finally implement the all features that I think they are needed for modern applications.

Next, I need to do many tests of SPVM module by creating modules and applications.

Documentations

The following are the official documentations of SPVM.

SPVM

Tutorial

SPVM Tutorial.

Tutorial

Language Specification

SPVM Language Specification.

Language Specification

Standard Functions

SPVM Standard Functions

Standard Functions

Standard Modules

SPVM Standard Modules.

Standard Modules

Performance Benchmark

SPVM Performance Benchmark.

Benchmark

Exchange API

SPVM Exchange API converts Perl data structures to SPVM data structures, and vice versa.

ExchangeAPI

Native API

SPVM Native API is C API used in SPVM native method.

NativeAPI

Some tricks for prettier xs

XS has a reputation of being ugly and cumbersome, but in my experience, it doesn't have to be. Let's take for example this snippet from my Thread::Csp::Promise class:

MODULE = Thread::Csp PACKAGE = Thread::Csp::Promise PREFIX = promise_

SV* promise_get(Promise* promise)

bool promise_is_finished(Promise* promise)

SV* promise_get_notifier(Promise* promise)

Please help test big pull request for DBD::Oracle

This large pull request hopes to solve segfault at cleanup and problems with multiple charsets in multiple connections to Oracle.

If you use DBD::Oracle please grab the PR and give it a try, then send your feedback.

https://github.com/perl5-dbi/DBD-Oracle/pull/147

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.