My Favorite Warnings: exiting

Perl has various ways to transfer control out of the normal flow: die(), goto(), return(), next, last, and redo are among the sorts of things I mean. Not all of these are suitable for all circumstances, and Perl issues an exiting warning for unsuitable cases.

Sometimes, though, you just need to do something unsuitable. When I write an interactive script, it generally dispatches to a subroutine named after the function, something like so:

Object::Pad review Yuki Kimoto's 2021-08-23 - Constructor argument customize

In this time, I review constructor argument customize. BUILDARGS can customize contructer argument. It is good enough for me. I think existing library that receive hash references as argument will have a slight performance penalty because a BUILDARGS function call.


Point->new($x, $y)

Perl Weekly Challenge 177: Damm Algorithm and Palindromic Prime Cyclops

These are some answers to the Week 177 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. 14, 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: Damm Algorithm

You are given a positive number, $n.

Write a script to validate the given number against the included check digit.

Please checkout the wikipedia page for information.

Example 1

Input: $n = 5724
Output: 1 as it is valid number

Example 2

Input: $n = 5727
Output: 0 as it is invalid number

The algorithm is a check digit algorithm named after H. Michael Damm, who presented it in 2004.

TWC 120: Task #1, Swap Odd/Even bits & Task #2, Clock Angle

TWC Task #1, Swap Odd/Even bits

jaredor submission for Task #1

I was just going to use a variation on last week's "Nybble Swap" task for this, but then I foolishly thought, "No, I've read Hacker's Delight I should twiddle bits!"

Okay, now that I told you about my first mistake, let me tell you, the bit twiddling was fun once it started working but I do have a little regret that it's straightforward bit-twiddling: I created a bit mask to pick out alternating bits, then just did the shifting and OR-ing you would expect to switch the even/odd bits. I can't help but wonder if there isn't some clever one-liner in Hacker's Delight. I can't claim to have remembered it even once though: I skimmed the book.

My Favorite Warnings: redundant and missing

The redundant and missing warnings were added in Perl 5.22 to cover the case where a call to the printf or sprintf had more (redundant) or fewer (missing) arguments than the format calls for. The documentation says that they may be extended to other built-ins (pack and unpack being named specifically) but as of Perl 5.34.0 only the printf() built-ins are covered.

I have (very occasionally) found myself writing a subroutine taking a printf-style format and some arguments, and letting the format specify which (if any) of the arguments actually appear in the output. If I just throw all the arguments after the format into the printf(), one of these warnings is very likely to be thrown, starting with 5.22, since use warnings; enables them by default.

How I Uploaded a CPAN Module

An updated but yet to be completed version is here.


So, accumulating effort from Wednesday, today(Friday) I become a CPAN contributor!

I got a PAUSE ID 2 weeks ago. If you are also interested in the Perl ecosystem, you may consider to apply for a PAUSE ID as well.

In this blogpost, I mainly follow the instructions here:

Some contents of the PerlMonks article are largely repeated here.

This piece of PerlMonks article is already 19-year-old, but it is still valid. One of the good things of the article is that you need not install new modules or programs if you are on a *nix system.

Prerequisites

One should have some knowledge on modules, packages and, not really necessary, object-oriented Perl ("Perl OO" in short).

TWC 119: Les Nybb and the Arrhythmic Trio

In which Raku solutions give shape to Perl solutions, and vice versa, and then Raku does what Raku does best.

Task 1: Swap Nibbles - basic and extended solutions in Raku and Perl.

Task 2: Sequence of symbols 123 without adjacent 1’s. Solutions in Raku and Perl, then a radically different approach that I would have never discovered in anything but Raku.

TWC 119: Task #1, Swap Nibbles & Task #2, Sequence without 1-on-1

TWC Task #1, Swap Nibbles

jaredor submission for Task #1

Hello everyone, I'm back after a year's absence, good to see everything is going as strong as ever. I have some extra time this weekend, so thought I'd try my hand at an answer again.

But, oh golly, looking back over my earlier posts on earlier problems was just painful--too many details! Going forward I'll just broad-brush things (and I mean it this time). If anyone has a question about details, then ask about them in the comments.

The swap nibbles problem is equivalent to a "swap hex-chars problem" and since we have the bigint module then any hex string can be represented by an integer. When a little investigation brought up that every bigint object has an as_hex() method, I found the restriction to positive integers less than 255 too restrictive: I decided to do them all! (Well, not quite all, since there are an infinite number of integers, but you know what I mean.)

My Favorite Warnings: once

The Perl compiler wants to help us write clean code. One of the ways that it does this is to issue warnings when a global variable appears ony once: Name "main::Foo" used only once: possible typo at ...

The thing is, sometimes this is not an error. For example, we may want to refer to a global variable in another package, one that was not imported into our namespace.

I have seen various expedients used to avoid this warning in CPAN code. Something like $Foo::Bar = $Foo::Bar = 42; is fairly typical. Sometimes this strange-looking code is commented as to its purpose, others not.

Alternatively, you can use the pragma no warnings 'once'; to supress this warning. This seems to me the appropriate way to spell "I meant to do that!" under the circumstances:

Object::Pad review Yuki Kimoto's 2021-08-21 - Constructor default argument

I start to review Paul Evans's Object::Pad from my personal thinking.

Latest years, Perl core teams positively try to implement Object-Oriented feature to Perl core. I hope my review helps a little.

First time is constructor default arguments.

# Perl Weekly Challenge 176: Permuted Multiples and Reversible Numbers

These are some answers to the Week 176 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. 7, 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: Permuted Multiples

Write a script to find the smallest positive integer x such that x, 2x, 3x, 4x, 5x and 6x are permuted multiples of each other.

For example, the integers 125874 and 251748 are permuted multiples of each other as

251784 = 2 x 125874

and also both have the same digits but in different order.

Output

142857

Monthly Report - June

Never been so busy ...

As you all know, I have recently started taking part in the weekly challenge again. I have always complained about the lack of time doing things I always wanted to do. But then it doesn't stop me taking up new projects. I have to learn how to prioritize projects. May be one day, I will get there. Right now I am actively working on 2 new projects simultaneously. First is preparing the talk for the upcoming Raku Online Conference. It is going to be my personal journey to Raku. And the second is very close to my heart, working on my first book about Perl in association with Dave Cross.

Announcing Date-ManipX-Almanac

One of the remarkable things about the Date-Manip package is its flexibility in the matter of input. If I mean "tomorrow noon," I do not have to think of what today is, I simply specify "tomorrow noon," or its equivalent in any of sixteen other languages.

One day, I thought: what about "tomorrow sunrise?" And thus was born Date-ManipX-Almanac.

In principal, there can be support for any almanac event from any astronomical body in the Astro::Coord::ECI ecosystem. In practice at least most of them are covered, though I have not audited for 100% coverage. This includes the bodies in the Astro-Coord-ECI-VSOP87D distribution, should you want planets through Neptune. Pluto was not covered by the VSOP models -- its exclusion is not a political statement, at least not by me. Satellites are not supported, and currently there are no plans for them.

Essence of Perl Text Processing - Perl Book

I published "Essence of Perl Text Processing" in Japan. This is 2021 new Perl Book(Both Normal Book and EBook).

Essence of Perl Text Processing

Mascot character is called Mojigaeru(This means String Frag).

"Kaeru(Gaeru/変える)" also means "replace" in Japanese. This expresses Perl is good at string searching and replacing.

Amazon Web Programming new Ranking #2 in Japan 2021-07-05

Amazon Web Programming new Ranking #2 in Japan 2021-07-05

Don't be ashamed of Perl. Be brave.

Perl Weekly Challenge 175: Last Sunday and Perfect Totient Numbers

These are some answers to the Week 175 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 July 31, 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: Last Sunday

Write a script to list Last Sunday of every month in the given year.

For example, for year 2022, we should get the following:

CPAN Bus Factor

Perhaps you've noticed a new metric when browsing MetaCPAN?

moose.png

What is "bus factor"?

Wikipedia defines "bus factor" as

a measurement of the risk resulting from information and capabilities not being shared among team members, derived from the phrase "in case they get hit by a bus."

For CPAN our definition is "a measurement of how risky it might be to start relying on a CPAN module, which might not be actively maintained".

Read the full post.

Promotion: Knight's Challenge

knight.png(image from wikipedia)
PROMOTION:

A coding puzzle for “The Weekly Challenge ‐ Perl & Raku” I made has been released this week!

You have 46- hours to play with it if you align with official deadline. It probably spends you 2~5 hours in this weekend. Beware! Doing the bonus part may spend you a block of extra 2 hours or more.

I wish more people will participate and show different approaches to the task. (And, may the participant give me some feedback as a puzzle creator?)

One may have advantage if s/he has played chess.

As the puzzle creator, of course I had a sketch of a solution in my mind.

Yesterday I solved (== coded) the puzzle and is blogging about it this morning. [Spoiler Alert] If you are interested in my solution... source code , blogpost

Miscellaneous:

My blog is moved to GitHub, mainly because I think soon or later I will blog on other programming languages or issues. At this moment, it has a few posts. :o)


What they say in Java is just as true in Perl

use Benchmark::Dumb 'cmpthese';

( $bar, $quux ) = qw( bar quux );

cmpthese( 0.0002, {
  conc => q{
    my $str = "xxx ";
    (((( $str .= "foo" ).= $::bar ).= "baz" ).= $::quux ).= "qux";
  },
  intp => q{
    my $str = "xxx ";
    $str .= "foo${::bar}baz${::quux}qux";
  },
} );

Perl Weekly Challenge 174: Disarium Numbers in dc

This blog is an answer to the first task (Disarium Numbers) of the Week 174 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Originally, the Perl Weekly Challenge called for solutions in Perl and Raku (also known as Perl 6 at the time). But, very soon, people started to provide solutions in other “guest” languages. See for example my blog post providing solutions to the task described below in about 18 different guest languages.

One of the languages I tried for the first time last week with Sylvester’s sequence is dc, and it turned out to be much more difficult and challenging than I initially thought. One of the problems is that there is only very limited documentation on this old programming language. So I thought it might be useful to describe in some details how I solved it. I provided detailed explanations in this other blog post. I’ll now do the same with the disarium number task of this week, which is a bit more complicated.

Next stable DBD::SQLite will be released around the end of July

DBD::SQLite 1.67_07 (with SQLite 3.36.0) is a release candidate for the next stable DBD::SQLite. This release has a notable change to improve how to deal with Unicode/Latin-1 characters, contributed by Felipe Gasper. If you write a new application, it is recommended to use one of the newly added modes like this:

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.