My Favorite Warnings — A Belated Introduction

Look, that's why there's rules, understand? So that you think before you break 'em. — Terry Pratchett, in Thief of Time.

A couple installments into this series of blog posts, I realized an introduction to Perl warnings would be appropriate, with some words on how to turn them off, and why you probably do not want to. Yes, this should have been the first post in the series, but I didn't know it would actually be a series, and, well, maybe better late than never.

The Perl compiler/interpreter can emit warnings when it finds things that may indicate a problem with the code. These are not (yet) enabled by default, but experience has shown that enabling them can highlight conceptual and logic errors.

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

Object::Pad Yuki Kimoto's 2021-08-25 - Default internal data structure of the object

Object::Pad Yuki Kimoto's 2021-08-25(I fix this entry because default internal data structure is array reference, not hash reference).

This time is default internal data structure of the object.

Default internal data structure of the Object::Pad is array reference.

Monthly Report - July

Never been so busy ...

The guilt is killing me every time I delay the monthly report. I finally found time to get this out on 22nd day of the month where I would do that on the very first day of the month in the past.

Life can be challenging at times, balancing personal and professional aspect can be difficult, I must confess.

In all of these up and down, I have to keep myself motivated and find ways to stay happy.

I try to avoid negative thoughts coming on my way and stay positive.

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:

Perl Weekly Challenge 126: Count Numbers and Minesweeper Game

These are some answers to the Week 126 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 August 22, 2021 at 24:00). 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: Count Numbers

You are given a positive integer $N.

Write a script to print count of numbers from 1 to $N that don’t contain digit 1.

Example

A dream realized

Have you heard that they are finally putting together a proposal to add a clean modern OO system into the core of Perl?

If you haven’t, I strongly encourage you to look over the RFC for Corinna, or at least watch Ovid’s excellent presentation on the project.

It’s reassuring that the list of contributors to the proposed design includes some of the most highly respected names in the Perl community, many of whom have previously taken one (or more!) tilts at this particular object-oriented windmill.

Indeed, over the past two decades I too have repeatedly attempted to design and prototype richer and more robust OO systems for Perl, starting way back in the previous millennium with a brief stint as the maintainer of Class::Struct, and continuing on though the release of modules such as Class::Std, Class::Delegation, and most recently: Dios.

Making Taint support optional in Perl

One of the changes to Perl that we're considering on p5p (the perl5-porters mailing list) is the removal of taint support. The first step towards that is to add a Configure option that lets you build a Perl without taint support.

In this post I'll explain what we're considering, and why. The purpose of this post is to let everyone beyond p5p know about this, and give you a chance to comment.

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:

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:

TWC 124: Literalism and existence proofs in the service of stress reduction

Again another week where I solve one answer and punt on another.

TWC Task #1, Happy Women Day

jaredor submission for Task #1

Well, "solve" may be a strong word for what I did with this problem, at least for my programming conscience. The problem statement was simple, but had no requirements for an acceptable solution other than what you could infer from the example solution in the problem statement. However I did give not one, but two solutions, so that's not totally lazy, even if each, on its own, is lazy, right?

--lazy solution

EV charge calculator from script to Dancer web

Since my last post I wanted to take my EV charge calculator script and convert it into a web form. In this post I breakdown how I migrated the script to a Dancer2 web app.

Just a minor note for those readers who may not be aware, Dancer2 is a "lightweight web-framework for Perl" as described in Dancer2 documentation and can be similar in comparison to Ruby Sinatra and Python Flask.

I started by creating a new project folder with the dancer2 program ( # please note that I am working on a Windows PC and on a linux OS the program would just be named dancer2 )

dancer2.bat -a EVCalc


I then copy over the files inside this directory to my project repository as shown in this commit and moved all the scripts to the bin directory as shown in this commit

I wrote a script to covert the electric rate csv file into a module and added all the calculation code in the main project module. All the html markup is stored in this template file and I sprinkled some CSS which renders a page similar to the screenshot below after submitting some data for calculating the charge of an EV :

calculator_page.png

Thank you for your time, I hope you enjoyed my post.

Railroad diagrams for SQL 2003 and SQL 2016

On github at https://github.com/ronsavage/SQL you will find a repo of SQL stuff created by Jonathan Leffler.

I recently added some files for SQL 2003 and SQL 2016, created by Domingo Alvarez Duarte.

Specifically, look for:
o sql-2003-2.ebnf
o sql-2003-2.ebnf.readme
o sql-2003-2-railroad-diagrams.xhtml
o sql-2016.ebnf
o sql-2016.ebnf.readme
o sql-2016-railroad-diagrams.xhtml

I'd suggest downloading the *.xhtml files and viewing them locally, rather than hammering the on-line convertor mentioned in the readme files, which accepts *.ebnf files and displays these railroad diagrams.

And that begs the question: Is there any Perl code which converts a grammar into a railroad diagram?

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

TWC: Punting to MJD and Showing Q&D Geometry

JIT blogging

I'm always doing other things and then Sunday comes and I start thinking, "How much time do I have before it's midnight in London?"

When "The Perl Challenge" first started, I was happy to just ponder the problems. Then came the pandemic and I thought that I would use some of my then copious free time to contribute. Then time got not-so-copious. And more people started contributing to TWC, some people much more talented than me, it turns out.

So I'll take a stab at things when I can and I'll still try to write a stand-alone script the way (I wish) I would at work, but my threatened laxness in writing things up will be more of a promise: Light banter to cast a veneer of confidence on the correctness of my results, anything else is extra.

TWC Task #1, Ugly Numbers

Higher Order Perl, Chapter 6, "Infinite Streams," Section 6.4, "The Hamming Problem"

Are you using Cache::Memcached and its ->stats method?

It's very slow if you have more than a few thousand keys in memcached. Not an unusual use case I think? I've got a fix here, which appears to DTRT: https://rt.cpan.org/Ticket/Display.html?id=138133. Maybe? I didn't spend too long looking at memcached's low level wire protocol.

The patch passes all the module's current tests and works for us. It took our CPU load from being pegged at 75% all of the time to being idle. So, if you're using Cache::Memcached, and the ->stats method (which isn't in the XS version of the module) then you might want this patch.

On that note - who is maintaining Cache::Memcached? The last release was in 2012. This isn't a high river module, but any app of significant size or age is *probably* using it and if they're using the ->stats method then ... Sure there's the ::Fast version, but I suspect this version is in a lot of places.

So if you know someone who knows someone who can prod the current maintainers then please point them at this post/patch. If you're using Cache::Memcached then perhaps try out this patch as well.

Random Thought: Exposure of Perl in the Academic Circles

Today I have wandered on the famous academic paper archive and suddenly a thought popped into my mind - use Perl as the keyword in searching.

Computer science papers with "Perl" in the title
https://arxiv.org/search/advanced?advanced=1&terms-0-operator=AND&terms-0-term=Perl&terms-0-field=title&classification-computer_science=y (8*)

Computer science papers with "Lisp" in the title
https://arxiv.org/search/advanced?advanced=1&terms-0-operator=AND&terms-0-term=Lisp&terms-0-field=title&classification-computer_science=y (12**)

Computer science papers with "Ruby" in the title
https://arxiv.org/search/advanced?advanced=1&terms-0-operator=AND&terms-0-term=Ruby&terms-0-field=title&classification-computer_science=y (6***)

Computer science papers with "Julia" in the title
https://arxiv.org/search/advanced?advanced=&terms-0-term=Julia&terms-0-field=title&classification-computer_science=y (53 ****)

For Haskell: ~50

For Java: ~249

For Python: ~357

For Perl Data Language (PDL): 0

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

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)

On the eve of CPAN Testers

Have a look at the CPAN Testers reports for two TRIAL releases of the same module, one from 2 days ago, the other a little over 3 years ago:

Last time, reports started coming in within hours of the release; over 60% of the picture was there within a day; some 85% after 2 days; and the first wave of reports lasted a week.

This time, it took almost a day to even start getting reports, and the diversity has been much lower. 3 days in, reports are still absent for many platforms:

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.