Perl Weekly Challenge 244: Count Smaller

These are some answers to the Week 244, 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 November 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: Count Smaller

You are given an array of integers.

Write a script to calculate the number of integers smaller than the integer at each index.

Example 1

PDF document creation with Markup languages

New, powerful features have recently been added to PDF::Builder and PDF::Table, enabling faster and easier high-level generation of PDF documents. The versions are respectively 3.025 and 1.005, and are available on CPAN.

This week in PSC (095) | 2023-01-27

A busy meeting today, we talked about quite a few things:

  • Smartmatch deprecation continues. Some upstream PRs have been raised, awaiting CPAN releases
  • Refaliasing might be able to be deëxperimentalized if we add a warning on the currently-failing closure capture cases
  • RFC0013 highlights a deficiency in the overload.pm API shape. Perhaps an opt-in new calling convention is required to make it more flexible. Paul will write another post to the mailing list with more detail
  • Mithaldu’s objection to the suggestion to deprecate map EXPR, LIST suggests that maybe a more powerful debugger “run until next statement” command would be good
  • The interaction of List::Keywords + autovivification highlights the overall problem with highly-pluggable extensible systems - sometimes extensions conflict. We just have to keep this in mind and not have too high expectations that “everything will be fine if we load 20 different plugins”
  • That said, maybe there are some CPAN extensions that ought to be part of the core language - autovivification for example
  • We’ve run out of devel release volunteers now. We need some people to volunteer for 5.37.9, .10, .11, (maybe .12?). Also maybe 5.38.0

My Favorite Modules: PerlIO::via

OK, I confess: PerlIO::via is not a module that I use every day. It allows you, easily, and with minimal code, to modify an I/O stream before it gets to the reader of the stream. or after the writer has written it. All you do is write (say) My::Module conforming to the parts of the PerlIO::via interface you need, and provide it to the second argument of open() or binmode() as ':via(My::Module)'. How cool is that? And how cool is a language that lets you do that with a minimum of fuss, bother, and code?

I encountered this when trying to modify (OK, hack) the behavior of a large and complex hunk of Perl not under my control. Rummaging around in this turned up the fact that all file input went through a single module/object, which had an open() method. I realized if I could insert my own PerlIO layer into the input stream, I would have control over what the victim host code saw.

Perl Weekly Challenge 243: Floor Sum

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

Spoiler Alert: This weekly challenge deadline is due in a bit more than a day from now (on November 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 2: Floor Sum

You are given an array of positive integers (>=1).

Write a script to return the sum of floor(nums[i] / nums[j]) where 0 <= i,j < nums.length. The floor() function returns the integer part of the division.

Example 1

Perl Testing in 2023

With my open source work, I've historically taken an approach which relies more on integration testing than unit testing, but with some of my newer projects, I've tried adopting principles from $paidwork and applying them to my free software.

This is a quick run-down of how I'm structuring my test suite in newer projects. It's likely that many of my existing projects will never adopt this structure, but some may.

Using Perl to prepare sequencing files to submit to NCBI's GEO

In the middle of a manuscript submission that requires sequencing data to be uploaded to NCBI's Gene Expression Omnibus.
This is a fairly standardized and (painful!) process that requires one to assemble their sequencing data (a collection of hundreds or thousands of files in the FASTQ format), put them in a single (very large) folder, compress them, generate md5 hashes and then upload them to GEO's FTP site.
There are a couple of tutorials available e.g. here and there that mostly cover the use case of one having assembled the files into a single fastq.
Our project used Oxford's Nanopore platform which store's its data as a series of fastq files, each holding a user defined number of sequences (in our case 2,000). Some of the experiments had generated an excess of 10M reads, so we are talking about a serious number of files to process:


  1. uncompress (if compressed)

  2. concatanate

  3. compress

  4. hash using md5sum

This week in PSC (094) | 2023-01-20

PSC met today, all three of us attended.

We discussed:

  • HAARG’s map my $x RFC. Overall thoughts are good, with one or two minor questions we’ll add as comments.
  • Whether the additions to join() as part of RFC0013 should be gated by some sort of opt-in flag, so as to avoid surprises. Either a feature flag for the caller of join(), or a use overload import option.
  • Maybe renaming the RFC process itself (because of the ambiguity with IETF’s RFC) and improving the numbering system. More discussion needed.

Perl Weekly Challenge 243: Reverse Pairs

These are some answers to the Week 243, 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 November 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: Reverse Pairs

You are given an array of integers.

Write a script to return the number of reverse pairs in the given array.

A reverse pair is a pair (i, j) where: a) 0 <= i < j < nums.length and b) nums[i] > 2 * nums[j].

Example 1

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

(1, 4) => nums[1] = 3, nums[4] = 1, 3 > 2 * 1
(3, 4) => nums[3] = 3, nums[4] = 1, 3 > 2 * 1

Example 2

OTOBO supports the German Perl/Raku-Workshop

We are happy to announce that Rother OSS again supports the German Perl/Raku-Workshop as a sponsor.

Since 2011, Rother OSS GmbH, based in southern Germany and with a team throughout Germany, has relied on the combination of an open source ticket system and business services from experts. Specifically: consulting, development and support for the free OTRS versions.

Util::H2O and More, during Ordinary Times

Background

During the 2022 Perl Advent, in particular the entry for December 06; Perl Advent fans were introduced to a little module called Util::H2O.

A lot has already been said about Util::H2O, and this author uses it a lot in client and production code because it helps produce very clean and maintainable HASH reference heavy code. So much so, that he created the Util::H2O::More module to encapsulate some common tasks and additional capabilities for working between pure Perl data structures and blessed objects that have real data accessors, in a natural and idiomatic way.

Support for Generic Perl Data Structures

h2o is perfect for dealing with data structures that are made up of strictly HASH references, but it is often the case that useful data structures contain a mix of HASH and ARRAY references. For example, when using databases or web API calls returning JSON, it is often a list of records that is returned. This was the case of the example call that was in the December 06 Perl Advent 2022 article.

My Family and Other Fish (PerlayStation Part 2)

Faced with any problem, there are many potential approaches. This, I have realised, is amply illustrated by the members of my own family, further reinforcing the educational value of having one. I shall anonymise them for my own protection, and as a disclaimer also state that everything I say about them or anything at all is probably wrong. In fact I have already issued my daily, pre-emptive, unspecified apology to my wife. For me, game coding in Perl is no different.

Identify Problem

Perl Weekly Challenge 242: Flip Matrix

These are some answers to the Week 242, Task 2, 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 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 2: Flip Matrix

You are given n x n binary matrix.

Write a script to flip the given matrix as below.

Regexp Delimiters

Perl lets you use almost anything as a regular expression delimiter. It is usual to use punctuation of some sort, but characters that match /\w/ can be used provided there is white space between the operator and the delimiter: m X foo Xsmx compiles and matches 'foobar'. In the presence of use utf8; you can go wild.

A query on the Perl 5 Porters Mailing List (a.k.a. 'p5p') a few days ago asked for opinions about appropriating the colon (':') as a delimiter for modifiers to the regular expression operators. This got me wondering about what regular expression delimiters were actually in use.

I scratched that itch by plowing through my local Mini CPAN, running everything that looked like Perl through PPI, and checking anything that parsed to an object of one of the relevant classes. A summary of the results is appended.

How to prevent an infinite loop

This loop (assuming you have an /etc/passwd and may read it) runs forever:

while () {
  open my $fh, '<:unix', '/etc/passwd' or die $!;
}

This loop terminates:

while () {
  open my $fh, '<', '/etc/passwd' or die $!;
  binmode $fh, ':unix';
}

Note that you will have to live with some extraneous output:
Too many open files at t.pl line 2.

Btw, you can make it loop forever again this way:

require POSIX;
while () {
  open my $fh, '<', '/etc/passwd' or die $!;
  binmode $fh, ':unix';
  POSIX::close fileno $fh;
}

The Perl Toolchain Summit is back in 2023!

After a three years pandemic-induced hiatus, it is my pleasure to announce that the Perl Toolchain Summit is happening again!

This year, for the thirteenth edition, we will be gathering again in Lyon, from Wednesday April 27 to Sunday April 30 2023, in the hotel Campanile Lyon Centre Part-Dieu. Participants will stay at the hotel, and work in the meeting rooms dedicated for the event.

The first rounds of invitations have been sent. We plan on having about thirty participants. We are always looking for sponsors (ask for our sponsor prospectus!).

Perl Weekly Challenge 242: Missing Members

These are some answers to the Week 242, 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 November 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: Missing Members

You are given two arrays of integers.

Write a script to find out the missing members in each other arrays.

Example 1

Input: @arr1 = (1, 2, 3)
       @arr2 = (2, 4, 6)
Output: ([1, 3], [4, 6])

(1, 2, 3) has 2 members (1, 3) missing in the array (2, 4, 6).
(2, 4, 6) has 2 members (4, 6) missing in the array (1, 2, 3).

Example 2

This week in PSC (093) | 2023-01-13

Paul, Philippe, and Rik had our regular call today to talk about perl5.

We put together some notes (at long last) for The Perl Foundation to use in their annual prospectus.

We talked about Math-Complex, and moving its issues into Perl5 GitHub. (A nice bit of work for anybody to do, but not groundshaking.)

We got back to the question of making Perl do SSL out of the box. Paul’s question was, “Can we bundle the CPAN dists for doing this and basically CPAN-install them at the end of normal install?” Audacious, but plausible!

We talked about the upcoming release of v5.38. Sure, it’s months away, but the various code freezes are approaching. What stuff needs work? One thing we did especially was review what experiments might be able to be deëxperimentalized. We talked about the refaliasing feature, which remains broken on closures, a total showstopper. Paul wonders if we can reduce the scope of how the feature can be used. For example: what if you must also use declared_refs?

Geizhals Preisvergleich sponsors the German Perl/Raku Workshop

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

Fosdem mini grants for 2023

One of the goals TPRF would like to achieve, now that conferences are becoming increasingly available in person, is to spread awareness of current Perl and Raku projects.

In support of this goal, TPRF will be issuing a limited number of mini grants of up to $300 to participants interested in holding Perl/Raku based talks in FOSDEM 2023 dev rooms. TPRF has made an intentional decision to not apply for a dev room, but to encourage talks to be given in other, non-language specific dev rooms instead. This will allow Perl and Raku to be shared with new audiences.

In addition, TPRF will have a 2 day stand at FOSDEM and are in need of volunteers to staff it. Stand volunteers are also eligible to apply for a mini grant of up to USD$300 to assist with the cost of attending.

To apply for a FOSDEM mini grant, please send a completed application to fosdem2023-grants@perlfoundation.org.

If you have questions, please join our fosdem slack channel, leave a comment below, or send a message to hello@perlfoundation.org

(Also on TPF news)

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.