Perl Weekly Challenge #214 - Rank Score

Just one weekly challenge entry this week, because I am lacking in time and have no idea how to efficiently solve the second challenge.

So here goes:

Rank Score

First, the code:

Experiments in Overloading

Let's play with overloading a little.

A simple class:

  package Local::Overloaded {
    use Moo;
    
    has number => ( is => 'ro' );
    
    use overload '0+' => sub {
      my $self = shift;
      return $self->number;
    };
  }

And let's test it:

  use Test2::V0;
  my $obj = Local::Overloaded->new( number => 42 );
  is( 0+$obj, 42 );
  done_testing;

This test fails.

Why?

Perl Weekly Challenge 251: Concatenation Value

These are some answers to the Week 251, 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 January 14, 2024 at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: Concatenation Value

You are given an array of integers, @ints.

Write a script to find the concatenation value of the given array.

The concatenation of two numbers is the number formed by concatenating their numerals.

Text::Extract::Word, MsOffice::Word::Surgeon - Weekly Travelling in CPAN

Destination: Text::Extract::Word
Date of Latest Release: Mar 09, 2012
Distribution: Text::Extract::Word
Module version: 0.02
Main Contributors: Stuart Watt (SNKWATT)
License: The Artistic License 2.0
Date of Latest Release: Jan 26, 2023
Distribution: MsOffice::Word::Surgeon
Module version: 2.01
Main Contributors: Laurent Dami (DAMI)
License: The Artistic License 2.0

Notice

Perl Weekly Challenge #213 - The Simple and the Hard

Hey everybody, back this week with a couple really interesting weekly challenge tasks. The first one is extremely simple, like one-liner simple, and the second one is quite complex and nearly 90 lines long.

Challenge #1 - Fun Sort

This was fun, it's in the name. This challenge took me about 5 minutes. Sort the input, split into even and odd arrays and put them together to print out. Pretty self-explanatory.

#!/usr/bin/perl
use strict;
use v5.24;

my (@even, @odd);
$_ % 2 ? push @odd, $_ : push @even, $_ for sort @ARGV;
say @even, @odd;

Challenge #2 - Not Fun Dijkstra

The first line of Perl_CGI script, env perl vs perl only, how different?

Hi ! Everyone there ! How are you ?

Until recently I runs all of my Perl scripts as well as Perl_CGI scripts by starting the folowing salutation,

#! /usr/bin/perl -w

The script with this beginning runs well at BASH shell at (/home/mkido/bin) LINUX such as Fedora, Ubuntu, Rocky (Alma-derivative). However, almost right now I noticed some of Perl example around has the different first line as below,

#! /usr/bin/env perl

And it doesn't seem to run at HOME BASH shell (/home/mkido/bin) by simple way of executing it by-itself by the command line. Will someone explain me about what is this [env perl] stuff? Thank you so much.

Mitsuru Kido

This week in PSC (101) | 2023-03-17

Porters,

We had an abbreviated PSC call today, largely due to an unexpected delay.

We discussed offering split-up deprecation categories, so you can no warnings 'deprecated::.xyz' and re-affirmed that we want to do this.

We talked about improving the backcompat of strict-vs-version behavior for use vX where X is older than v5.36 and agreed we’d bring that back, but wanted to discuss more about other related changes to the use-vX code.

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:

Perl Weekly Challenge #212 - Spinning Letters and Chopping Numbers

Back already with this week's solutions to the PWC #212. Spoiler alert, because the challenge doesn't close for another few days if you want to have a try.

Challenge #1 - Spinning Letters

This week we've got a simple letter rotation. Take each letter of the word provided and rotate it by each number in the list. At first I thought this would be a lot longer code. i even put it in a sub. That actually doubles the size though for absolutely no benefit, so I just simplified. We split the word, then loop through the letters and apply the rotation. If it wraps we start from the start of the alphabet. Upper-case is handled with a simple test to insert the right case of each character. Then we don't even bother putting the word back together again because we can just say it as-is.

Template Toolkit’s DEFAULT is not too useful

Quoth the fine manual for Template Toolkit:

The DEFAULT directive is similar to SET but only updates variables that are currently undefined or have no "true" value (in the Perl sense).

Nice. Basically, where SET is like the = operator in Perl, DEFAULT is like the ||= operator. Quite useful! If it were, that is. Because the analogy is only superficially true.

Quiq - Weekly Travelling in CPAN

Destination: Quiq

Date of Latest Release: Feb 04, 2023
Distribution: Quiq
Module version: 1.207
Main Contributors: Frank Seitz(FSEITZ)
License: The Artistic License
Source: https://github.com/s31tz/Quiq

Quiq is a "Perl class library for rapid development". The modules are "designed according to uniform principles" (translated from German).

Quiq contains 234 (Ooooops!!!) classes at the time this post is being written and their descriptions are mostly written in German.

It contains several text-based document/markup language code writers, namely Quiq::Tag (for XML), Quiq::Html::MODULES, Quiq::MediaWiki::Markup, Quiq::Css, Quiq::LaTex::MODULES; some network functionalities including Quiq::Http::MODULES, Quiq::Ssh and Quiq::Socket ; some tiny tools like Quiq::Color and Quiq::Stopwatch; some system tools like Quiq::Path, Quiq::TempFile and Quiq::Process; some modules for meta-development including Quiq::Hash and Quiq::Object; some modules for general use like Quiq::Converter, Quiq::Math and Quiq::Epoch. ...


For CSS, we have Quiq::Css :

ChatGPT for Perl Learning

How to learn Perl has been an eternal problem for the Perl community. Compared to many other languages that place an emphasis on teaching the basics and using education as a tool for evangelism we've had sporadic efforts along those lines. Given the size of our community and the fact that the best programmers are often in great demand, we have a hard time pumping out the needed docs and examples.

I've been using ChatGPT quite a lot lately and find that although it makes some mistakes it actually churns out pretty decent Perl if given good instructions. For example here's one I did this AM. We just had the dreaded hour shift here in the US and I'm just not up to thinking so I asked Chat GPT:

"write a perl subroutine that accepts two hashrefs and a list. For each item in the item merge the hashrefs by combining the values into an array ref. "

Here's what it pumped out:

Perl Weekly Challenge #211

A couple very very last-minute solutions to the Weekly Challenge #211. I was crammed for time, so I didn't get to these until the last minute.

Challenge #1

For challenge number 1 I had an idea of the method I would use, but since I've been experimenting with it anyway, I asked ChatGPT for its ideas as well. Because of my lack of time, I wanted to get some help with the design process. ChatGPT is amazing at both developing and describing an algorithm in simple terms to make it understandable. I based my solution somewhat off the AI's algorithm, but I did write it entirely by hand. It's pretty simple, it just iterates across the matrix and makes sure everything matches its diagonal neighbor prior to it.

Another thing you might notice this week is that I actually put my solutions into functions, not just a basic script. Anyways, here it is:

Perl Weekly Challenge 250: Alphanumeric String Value

These are some answers to the Week 250, Task 2, of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Task 1: Alphanumeric String Value

You are given an array of alphanumeric strings.

Write a script to return the maximum value of alphanumeric string in the given array.

The value of alphanumeric string can be defined as

a) The numeric representation of the string in base 10 if it is made up of digits only. b) otherwise the length of the string

Example 1

This week in PSC (100) | 2023-03-10

All three of us met, and were joined by Pete Krawczyk who first wanted to discuss some TPRF-related issues.

Following on from this we discussed:

  • Zefram’s request to back out the strict-vs-VERSION changes. There’s some merit here, he sent a PR to undo the whole thing. We feel there’s two different issues that need looking at separately. Paul will explain some thoughts in more detail.

  • Yves’s request to reöpen discussions about deprecated:: warning categories. There may be benefit here too. Paul will write a followup response.

Call for Papers. TPRC 2023

Call For Papers is now open! You can submit your talk Ideas at https://tprc.to/papers. Talk submission deadline is March 31 Midnight UTC. Talks must be given live and in-person. If you are looking for any talk ideas, try out the conference wiki.

Visit the TPRC 2023 website at https://tprc.to/
Follow us on Twitter: @PerlConferences
Like us on Facebook: The Perl Foundation (@tpf.perl)
Subscribe to the mailing list: https://tprc.to/subscribe
Post a message to us at https://tprc.to/tprc-2023-tor/contact-us/

Regexp::Assemble - Weekly Travelling in CPAN

It has been on my mind quite a while. Originally it was suggested on Twitter, by Mohammad Anwar, the maintainer of "The Weekly Challenge", that the community should re-publish the CPAN Weekly, which existed before I joined the hacker community. Our plan was having the newsletter began in December 2022. Actually that collided with the Advent Calendar, so, not a good time. Anyway, after many twists and turns, I was busy in late 2022 and early 2023 for job hunting (settled now). Now I try to act as a tour guide and visit some CPAN modules (or distributions) with you in a causal manner.

Destination: Regexp::Assemble

Date of Latest Release: Jun 20, 2017
Distribution: Regexp-Assemble
Module version: 0.38
Main Contributors: David Landgren and Ron Savage(RSAVAGE)

Regexp::Assemble is used for combining regular expressions.

my $ra = Regexp::Assemble->new;
$ra->add('cat', 'rat');
say $ra->re;
say $ra->as_string;
# (?^:[cr]at)
# [cr]at

The two methods of the module you will probably use most frequently, as_string and re , have subtle differences:

Perl Weekly Challenge 250: Smallest Index

These are some answers to the Week 250, Task 1, of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Task 1: Smallest Index

You are given an array of integers, @ints.

Write a script to find the smallest index i such that i mod 10 == $ints[i] otherwise return -1.

Example 1

Input: @ints = (0, 1, 2)
Output: 0

i=0: 0 mod 10 = 0 == $ints[0].
i=1: 1 mod 10 = 1 == $ints[1].
i=2: 2 mod 10 = 2 == $ints[2].
All indices have i mod 10 == $ints[i], so we return the smallest index 0.

Example 2

This week in PSC (099) | 2023-03-03

After missing last week, all three of us attended.

  • Recapped the missing weeks from absences
  • Smartmatch deprecation seems to be causing some BBC failures due to new warnings, but that’s to be expected; Philippe to submit patches upstream
  • Refined the questions surrounding SSL-in-core; Paul to send a follow-up email
  • RFC0013 needs some core changes to how overload works; best deferred for 5.39 now
  • Agreed to rename “RFC” to “PPC” (“Proposed Perl Change”)

TWC 205: Exclusive Third Or First

In which we ponder the highest bit, and find a much faster Max_XOR.

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.