Perl Weekly Challenge 191: Twice Largest and Cute List

These are some answers to the Week 191 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 November, 20, 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: Twice Largest

You are given list of integers, @list.

Write a script to find out whether the largest item in the list is at least twice as large as each of the other items.

Example 1

Writing a SNES assembler compiler/disassembler - Day 3

Assembling the Assembler

Grammar fix

When starting implementing the compiler part of this. I noticed that the grammar does not actually really work, especially if you introduce new lines. If I parse a file with 3 instructions, we catch the \n sometime and the asm-comment token is too greedy.

Let's change the ws rule to only capture horizontal blank (space and tab) and introduce an eol token, this makes the grammar more clear on what we are working on also.

PDL 2.063_01 released

There have been a couple of developments in PDL since the last announcement on here I could find, from 2013. To hypersummarise: 64-bit indexing, native complex number support, automatic pthreading using all available CPU cores, faster installation thanks to parallel-building, memory-mapped data, repository hosted on GitHub, easy to use "with" Inline. Returning you to the announcement:

PDL 2.063_01 has just been released. Notable changes since 2.062:

  • Various API changes (see below)
  • Improvements to $MACRONAME() handling including that arguments can now contain (balanced) brackets
  • redodims no longer leaks memory
  • The PROJ.4 interface has been updated to use the PROJ v6+ interface, finally
  • A zeroes() regression from 2.057_01 where it ignored the type of an input PDL has been fixed
  • PDL::Compression is now thread-safe (thanks Derek for the report!)

An attempt has been made to fix the older-clang/LLVM compilation errors - if you have clang 12.0.0 or earlier and can try installing this version and report results here, that would be very helpful!

My Favorite Warnings: syntax

Warnings category syntax contains a number of sub-categories representing possibly-problematic syntax. These include ambiguous syntax, problematic bareword usage, invalid printf conversions, and more. But there are also syntax diagnostics that do not fall under any of the sub-categories. These tend to be a miscellaneous group, and a normal-sized blog post can do no more than to give a sample.

What brought this to my attention was a noisy test in Template-Toolkit. under Perl 5.35.2 and up. The noisy code was untainting a variable using code like

$foo = each %{ { $foo => undef } } if ${^TAINT};

This makes use of the fact that hash keys are (so far) never tainted. The new warning was each on anonymous hash will always start from the beginning.

Perl Weekly Challenge 190: Capital Detection and Decoded List

These are some answers to the Week 190 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 November, 13, 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: Capital Detection

You are given a string with alphabetic characters only: A..Z and a..z.

Write a script to find out if the usage of Capital is appropriate if it satisfies at least one of the following rules:

1) Only first letter is capital and all others are small. 2) Every letter is small. 3) Every letter is capital.

Example 1

Input: $s = 'Perl'
Output: 1

Example 2

A (not so) simple matter of privacy

You may have seen Ovid's recent post on his discussions with the Perl Steering Committee about moving forward with implementing an initial subset of the Corinna proposal in the Perl core.

One of the issues that came up during those discussions was the best way to provide private methods in Corinna. The current Corinna proposal is that this would be done (like almost everything else in Corinna) via an attribute:

method do_internal :private () {...}

Thereafter, the do_internal() method can only be called from within the current class, and is never overridden by derived-class methods when it is called within its original class.

In other words, the :private method effectively prepends the following code to the start of the method:

croak "Can't call method 'do_internal'"
    if caller ne __CLASS__;

JavaScript Supported Web Scraping using Perl and Selenium

Perl Club starts to translate Japanese Perl Tutorial to English. Yuki Kimoto is one of the Perl Messengers.

Perl Club decides to write all articles English at first.

This is a first English-first article.

If you want to scrape web contents, this article explains how to scrape web contents using Perl and Selenium.

JavaScript Supported Web Scraping using Perl and Selenium


I explain JavaScript supported web scraping using Perl and Selenium::Remote::Driver. Selenium::Remote::Driver is a Perl module for Selenium. Selenium provides the APIs for JavaScript supported web scraping.

Developing A Game Engine with Perl: Part 7 - Fork

Pssssst... I DO NOT KNOW WHAT I AM DOING.

If you want to start reading from the beginning. Check out the first article in this series

Continuing from our last post, I talked about how ANSI Game Engine is a colourful telnet server. We left off with needing to fork the engines telnet server.

Player 2 has joined the game!

Time to level up our telnet server and make it multi-player with some knify forky.

Image description

I've added in the strftime identifier from Perl's POSIX module to help with time stamping the output. The setsid identifier is for starting a new session and group ID for each forked process. A.K.A, the child process. :sys_wait_h is for returning without wait after the child process has exited, using the WNOHANG flag when calling waitpid(). This provides non-blocking wait for all pending zombie children.

Zombie Attack!!!

Perl Weekly Challenge 189: Greater Character and Array Degree

These are some answers to the Week 189 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 November, 6, 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: Greater Character

You are given an array of characters (a..z) and a target character.

Write a script to find out the smallest character in the given array lexicographically greater than the target character.

Example 1

Input: @array = qw/e m u g/, $target = 'b'
Output: e

Example 2

Input: @array = qw/d c e f/, $target = 'a'
Output: c

Example 3

Writing a SNES assembler compiler/disassembler - Day 2

First look at generating grammars

This will be very short even if that take me a lot of time to figure this part.

In my ASM65816Grammar.rakumod I manually wrote the Number and Addressing grammar but obiously for the instructions it's not really possible.

General ASM grammar

First let's focus on parsing something simple.

The basic gist of what you can write in an asm file is very short

lda $42 clc adc #3 cmp #0005:beq $4855 ; if $42 + 3 is 5 branch to $4855

You have an instruction per line, or you can have multiple instructions separated with a :, and ; are used to mark a comment.

Geizhals Preisvergleich sponsors the German Perl/Raku Workshop 2022

In 2022, the German Perl/Raku Workshop will take place in Leipzig. We are very happy to announce that long time Perl supporter Geizhals Preisvergleich sponsor the workshop.

Developing A Game Engine with Perl: Part 6 - A Colourful Telnet Server

I'll stop reminding you that... I DO NOT KNOW WHAT I AM DOING.

If you want to start reading from the beginning. Check out the first article in this series

What is ANSI Game Engine?

Well, at it's core, ANSI Game Engine is a very colourful and interactive telnet server.

Why telnet!?

Perl Weekly Challenge 188: Divisible Pairs and Total Zero

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

Task 1: Divisible Pairs

You are given list of integers @list of size $n and divisor $k.

Write a script to find out count of pairs in the given list that satisfies the following rules.

The pair (i, j) is eligible if and only if
a) 0 <= i < j < len(list)
b) list[i] + list[j] is divisible by k

Example 1

Input: @list = (4, 5, 1, 6), $k = 2
Output: 2

Example 2

Input: @list = (1, 2, 3, 4), $k = 2
Output: 2

Example 3

Input: @list = (1, 3, 4, 5), $k = 3
Output: 2

Example 4

Closures

A casual remark about closures which I made in My Favorite Warnings: redefine touched off a long off-topic exchange with Aristotle that I thought ought to be promoted to a top-level blog entry. The big thing I learned was that any Perl subroutine can be a closure. The rest of this blog will try to make clear why I now believe this. The words are my own, as are any errors or misconceptions.

The second sentence of Wikipedia's definition of a closure says "Operationally, a closure is a record storing a function together with an environment." This makes it sound a lot like an object, and therefore of little additional interest in an O-O environment.

Addressing CPAN vulnerabilities related to checksums

This blog post addresses checksum and signature verification vulnerabilities affecting CPAN, the cpan client, and the cpanm client, which were published in a security advisory on 23rd November 2021. If you're not aware of this topic, you might like to start by reading the advisory. This post gives a high-level description of the issues, what has been done to address them, what is still left to do, and what you should do. If you have any questions on this, you can add comments here, or email the PAUSE admins (modules at perl dot org).

Before we dig into the details, we'll first give an overview of how the relevant parts of the CPAN ecosystem work.

If you're not interested in the details, skip to the section "What do you need to do?"

TL;DR: make sure your CPAN client uses https and a trusted mirror – such as cpan.org

The Weekly Challenge - 1000 days

https://theweeklychallenge.org/blog/1000-days/

Perl Weekly Challenge 187: Days Together and Magical Triplets

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

Task 1: Days Together

Two friends, Foo and Bar gone on holidays separately to the same city. You are given their schedule i.e. start date and end date.

To keep the task simple, the date is in the form DD-MM and all dates belong to the same calendar year i.e. between 01-01 and 31-12. Also the year is non-leap year and both dates are inclusive.

Write a script to find out for the given schedule, how many days they spent together in the city, if at all.

Example 1

Input: Foo => SD: '12-01' ED: '20-01'
       Bar => SD: '15-01' ED: '18-01'

Output: 4 days

Example 2

My Favorite Warnings: shadow

Who knows what evil lurks in the hearts of men? The Shadow knows!

OK, Perl does not literally have a warning about a 1930's pulp fiction and radio serial character. But Perl 5.28 introduced shadow as a new warning category for cases where a variable is redeclared in the same scope. Previously, such warnings were under misc.

To tickle this it is sufficient to

$ perl -Mstrict -Mwarnings -Mdiagnostics -e 'my $x; my $x;'

If your Perl is at least 5.28.0, you get the diagnostic

Writing a SNES assembler compiler/disassembler - Day 1

Writing a SNES assembler compiler/disassembler

Why ? Because I can. More seriously I have a project where I need to inject new Snes code in a running game and I want to express directly this new code in my Raku component (A webserver service). I want to have special sub that returns me Snes bytecode but that contains Snes assembler.

I tried injecting a SLANG in Raku already. Like writing my $byte-code = SNES lda $42; sta $54; rtl; But it’s rather tricky and I will probably just have a additional Slang with its own grammar in a dedicated file.

Developing A Game Engine with Perl: Part 5 - 32bit -> 64bit & Perl's Storable

If you haven't heard already... I DO NOT KNOW WHAT I AM DOING.

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.