Published by Shiping on Friday 01 December 2023 02:28
While I'm trying to figure out a simple way to make a variable passed as a parameter to a subroutine immutable in the called subroutine, I came upon a webpage showing the following:
#!/usr/bin/perl # Function Definition sub Func(Int $variable) { # Operation to be performed $variable /= 2; } # Defining a local variable my $value = 20; # Function Call with local variable print Func($value);
Output:
Error: Cannot assign to an immutable value
Can anyone tell me what Perl version it's talking about? It talks about named parameters which can be set to be mutable or immutable, something I'm looking for, but the examples given don't work at all for me. I'm using Perl 5.26.3.
Published by /u/oalders on Friday 01 December 2023 00:10
Published by /u/perlancar on Friday 01 December 2023 00:03
![]() | submitted by /u/perlancar [link] [comments] |
Published by perlancar on Friday 01 December 2023 00:02
dist | author | abstract | date |
---|---|---|---|
Acme-CPANAuthors-InMostCPANAuthors | PERLANCAR | Authors who are listed in Acme::CPANAuthors::* the most | 2023-11-28T05:36:57 |
Acme-CPANAuthorsBundle-CPAN-Streaks | PERLANCAR | A collection of Acme::CPANAuthors::CPAN::Streaks::* modules | 2023-11-25T06:53:34 |
Acme-CPANModules-CPANAuthors | PERLANCAR | List of Acme::CPANAUthors::* modules | 2023-11-28T04:30:10 |
Acme-CPANModules-Locale-ID | PERLANCAR | List of modules related to the Indonesian locale (language, country) | 2023-11-12T00:06:19 |
Acme-CPANModules-SmartMatch | PERLANCAR | List of modules to do smart matching | 2023-11-05T00:05:29 |
Acme-DTUCKWELL-Utils | DTUCKWELL | The great new Acme::DTUCKWELL::Utils! | 2023-11-03T08:58:51 |
Acme-Thing | PERLANCAR | Represent anything as Perl (CPAN) module | 2023-11-26T00:06:07 |
Aion-Query | DART | functional interface for accessing database mysql and mariadb | 2023-11-01T09:14:33 |
Aion-Telemetry | DART | measures the time the program runs between specified points | 2023-11-01T12:23:16 |
Alien-Serd | ZMUGHAL | Find or build Serd RDF processor | 2023-11-09T18:38:12 |
Alien-Sord | ZMUGHAL | Find or build Sord in-memory RDF store | 2023-11-12T02:07:33 |
Alien-hdt_cpp | ZMUGHAL | Find or build hdt-cpp (RDF binary format library) | 2023-11-12T04:34:33 |
Alien-zix | ZMUGHAL | Find or build Zix C99 data structure library | 2023-11-09T17:56:33 |
AnyEvent-KVStore | EINHVERFR | A pluggable key-value store API for AnyEvent | 2023-11-15T01:45:31 |
AnyEvent-KVStore-Etcd | EINHVERFR | An Etcd driver for AnyEvent::KVStore | 2023-11-18T03:34:41 |
App-Bin-Search | SKIM | Tool to bitwise search of data in hexadecimal stream. | 2023-11-26T12:35:16 |
App-CPANStreaks | PERLANCAR | Calculate various CPAN streaks | 2023-11-25T05:12:55 |
App-DownloadsDirUtils | PERLANCAR | Utilities related to downloads directories | 2023-11-16T04:30:27 |
App-FileFindUtils | PERLANCAR | Utilities related to finding files | 2023-11-20T09:32:49 |
App-GUI-Juliagraph | LICHTKIND | drawing Mandelbrot and Julia fractals | 2023-11-17T03:45:30 |
App-Hack-Exe | DCHURCH | An animated terminal app that pretends to hack a website, just like in the movies | 2023-11-04T19:46:41 |
App-MARC-Leader | SKIM | Base class and script for parse and print MARC leader. | 2023-11-19T20:08:27 |
App-randquote | PERLANCAR | Print a random quote | 2023-11-19T00:05:05 |
App-wcgrep | PERLANCAR | Print lines matching a wildcard pattern | 2023-11-17T09:30:30 |
At | SANKO | The AT Protocol for Social Networking | 2023-11-22T03:45:18 |
Bandana | TROTH | Bandana – a light and powerful web framework | 2023-11-12T18:01:09 |
Bencher-Scenarios-Log-ger | PERLANCAR | Scenarios for benchmarking Log::ger | 2023-11-27T00:05:46 |
Business-TrueLayer | LEEJO | Perl library for interacting with the TrueLayer v3 API (https://docs.truelayer.com/) | 2023-11-29T08:34:16 |
CLI-Simple | BIGFOOT | Simple command line script accelerator | 2023-11-16T22:24:38 |
CPAN-API-BuildPL | LEONT | Documentation of the API for using Build.PL | 2023-11-04T12:03:44 |
CPAN-Static | LEONT | Static Installation for CPAN distributions | 2023-11-04T14:08:34 |
Chipcard-PCSC | WHOM | Communicate with a smart card using PC/SC from a Perl script | 2023-11-20T20:41:56 |
Complete-Color | PERLANCAR | Completion routines related to colors | 2023-11-30T10:19:49 |
Dancer2-Plugin-JsonApi | YANICK | JsonApi helpers for Dancer2 apps | 2023-11-15T19:24:49 |
Dancer2-Plugin-OpenAPI | YANICK | create OpenAPI documentation of your application | 2023-11-16T17:21:27 |
Data-MARC-Leader | SKIM | Data objects for MARC leader. | 2023-11-17T23:58:17 |
Database-ManagedHandle | MIKKOI | Manage database handles safely for long running processes | 2023-11-28T21:16:38 |
Database-Temp | MIKKOI | Create an ad-hoc database which drops itself automatically | 2023-11-28T21:15:00 |
Dist-Zilla-Plugin-InsertDistFileLink | PERLANCAR | Insert links to distribution shared files into POD as HTML snippets | 2023-11-09T08:08:46 |
File-Util-DirList | PERLANCAR | File utilities involving a list of directories | 2023-11-15T10:28:11 |
File-Util-Sort | PERLANCAR | Routines related to sorting files in one or more directories | 2023-11-26T08:59:52 |
File-Util-Symlink | PERLANCAR | Utilities related to symbolic links | 2023-11-30T08:17:57 |
File-Util-Test | PERLANCAR | Utilities related mostly to testing/checking for files in directories | 2023-11-17T02:42:09 |
Graphics-ColorNamesLite-EN | PERLANCAR | Lots of English color names and equivalent RGB values (lite version) | 2023-11-30T09:52:46 |
Graphics-ColorNamesLite-ID | PERLANCAR | Indonesian color names and equivalent RGB values (lite version) | 2023-11-30T09:53:08 |
Grpc-XS | JOYREX | binding to the grpc library. | 2023-11-01T18:55:33 |
Ixchel | VVELOX | Automate various sys admin stuff. | 2023-11-16T17:08:35 |
Locale-MaybeMaketext | RBAIRWELL | Find available localization / localisation / translation services. | 2023-11-13T23:48:31 |
MARC-Leader | SKIM | MARC leader class. | 2023-11-18T00:18:41 |
MARC-Leader-Print | SKIM | MARC leader class for print. | 2023-11-19T16:45:10 |
Mo-utils-Date | SKIM | Mo date utilities. | 2023-11-14T07:48:11 |
Mojolicious-Plugin-IsBot | RAWLEYFOW | A Mojolicious plugin that adds a helper to test if a request is a bot. | 2023-11-03T16:10:22 |
Music-Bassline-Generate | GENE | Generate walking basslines – DEPRECATED | 2023-11-12T04:12:43 |
Music-Bassline-Generator | GENE | Generate walking basslines – DEPRECATED | 2023-11-12T04:20:30 |
Object-PadX-Role-AutoJSON | SIMCOP | Role for Object::Pad that dynamically handles a TO_JSON serialization based on the MOP | 2023-11-15T15:30:02 |
Object-PadX-Role-AutoMarshal | SIMCOP | Automated nested object creation with Object::Pad | 2023-11-15T15:30:13 |
OpenAIAsync | SIMCOP | OpenAI style Client and Server for processing various AI tasks | 2023-11-23T14:06:33 |
OpenTelemetry-Exporter-OTLP | JJATRIA | An OpenTelemetry Protocol span exporter | 2023-11-07T20:56:16 |
OpenTelemetry-SDK | JJATRIA | An implementation of the OpenTelemetry SDK for Perl | 2023-11-01T00:00:34 |
PDK-Device | CARELINE | turns baubles into trinkets | 2023-11-26T11:13:57 |
PGObject-Util-LogRep-TestDecoding | EINHVERFR | Parse Pg's test_decoding messages | 2023-11-12T02:29:08 |
SPVM-Go | KIMOTO | Goroutines of The Go Programming Language | 2023-11-08T01:07:43 |
SPVM-Thread | KIMOTO | Native Thread | 2023-11-10T03:55:39 |
SPVM-Time-HiRes | KIMOTO | High Resolution Time | 2023-11-27T02:24:13 |
Seq | DAVIDRAAB | A lazy sequence implementation | 2023-11-21T00:38:56 |
Seq-Iter | PERLANCAR | Generate a coderef iterator from a sequence of items, the last of which can be a coderef to produce more items | 2023-11-21T03:30:18 |
Set-Streak | PERLANCAR | Routines related to streaks (longest appearance in consecutive sets) | 2023-11-23T15:02:15 |
Silicon-Chip-Btree | PRBRENAN | Implement a B-Tree as a silicon chip. | 2023-11-11T04:13:38 |
Spreadsheet-Examples | PERLANCAR | A collection of various examples of spreadsheet files | 2023-11-09T04:04:42 |
TAP-Formatter-GitHubActions | JGOMEZ | TAP Formatter for GitHub Actions | 2023-11-28T21:44:42 |
TableData-Perl-CPAN-Release-Static-2023 | PERLANCAR | CPAN releases for the year 2023 | 2023-11-20T02:27:50 |
TableData-Perl-CPAN-Release-Static-2024 | PERLANCAR | CPAN releases for the year 2024 | 2023-11-20T04:56:56 |
Test-CVE | HMBRAND | Test current release against CVE's | 2023-11-27T14:42:35 |
Test-Database-Temp | MIKKOI | Create temporary test databases and run tests in all available ones | 2023-11-28T21:16:49 |
TextDoc-Examples | PERLANCAR | A collection of various examples of word-processor text document files | 2023-11-17T08:07:28 |
Travel-Routing-DE-HAFAS | DERF | Interface to HAFAS itinerary services | 2023-11-16T20:28:48 |
WebService-Readwise | LANCEW | Perl module to interact with Readwise.io API:w | 2023-11-04T16:28:42 |
ipgrep | RRWO | grep files by CIDR | 2023-11-07T16:54:39 |
Number of new CPAN distributions this period: 78
Number of authors releasing new CPAN distributions this period: 32
Authors by number of new CPAN distributions this period:
No | Author | Distributions |
---|---|---|
1 | PERLANCAR | 26 |
2 | SKIM | 6 |
3 | ZMUGHAL | 4 |
4 | MIKKOI | 3 |
5 | KIMOTO | 3 |
6 | SIMCOP | 3 |
7 | EINHVERFR | 3 |
8 | JJATRIA | 2 |
9 | DART | 2 |
10 | GENE | 2 |
11 | LEONT | 2 |
12 | YANICK | 2 |
13 | PRBRENAN | 1 |
14 | RBAIRWELL | 1 |
15 | DTUCKWELL | 1 |
16 | WHOM | 1 |
17 | JGOMEZ | 1 |
18 | RRWO | 1 |
19 | LEEJO | 1 |
20 | LICHTKIND | 1 |
21 | DCHURCH | 1 |
22 | CARELINE | 1 |
23 | BIGFOOT | 1 |
24 | LANCEW | 1 |
25 | DAVIDRAAB | 1 |
26 | RAWLEYFOW | 1 |
27 | JOYREX | 1 |
28 | TROTH | 1 |
29 | DERF | 1 |
30 | SANKO | 1 |
31 | HMBRAND | 1 |
32 | VVELOX | 1 |
Published by Tiago Peczenyj on Thursday 30 November 2023 18:40
On Golang I have the function Unix from time package with the following spec
https://pkg.go.dev/time@go1.21.4#Unix
func Unix(sec int64, nsec int64) Time
It does
Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC
In other words, I am trying to decode a "datetime" from a given epoch in seconds + nanoseconds.
I find some alternatives to do the same in Perl such as
localtime($sec);
or using https://metacpan.org/pod/DateTime I have the constructor from_epoch
but in any case, I can only parse seconds, not nanoseconds.
Is there a way to do it easily in Perl (with or without external modules) or should I ignore the nanoseconds part since it may be irrelevant?
Published by Tiago Peczenyj on Thursday 30 November 2023 17:31
Few years ago, to start a project, like a module to be available via CPAN, I used Dist:Zilla and few plugins, perl critic, perl tidy, nyt proof, test::more, etc.
Now I'd like to create a simple project -- a parser for a specific base64 encoded message, it should contain a constructor to return an object with few methods and maybe some constants. Maybe a command line tool.
I just don't know how to start a project from scratch anymore.
I imagine my package will be stored in lib/ directory, I should add a Readme, t/ for tests, etc.
How should I start? Should I use Module::Build
and create a basic Build.PL
or there are more easier/interessant ways to do it on 2023?
And how about code linting, formatting, testing? is there something new or relevant to check or should I continue with the good old tools?
Thanks in advance
Published by leonerd on Thursday 30 November 2023 15:53
Capture perl5343delta, perl5363delta, perl5382delta
Published by leonerd on Thursday 30 November 2023 15:35
Add Perl versions 5.34.3, 5.36.3, 5.38.2 to perlhist.pod
Published by anaximander on Thursday 30 November 2023 14:20
I'm trying to draw a semi-transparent block onto an existing image using Perl's GD.pm.
My code looks like this:
use strict;
use GD;
my $img = GD::Image->new('cello.png');
GD::Image->trueColor(1);
$img->saveAlpha(1);
my $boxColor = $img->colorClosestAlpha(0,0,0,60);
$img->filledRectangle(0,300,600,400, $boxColor);
open(FH, '>', 'cello2.png') or die $!;
binmode FH;
print FH $img->png();
close FH;
This draws a black box on the image, but the box is completely opaque as if the alpha channel is being ignored. Any suggestions would be greatly appreciated.
Published by Priyansh Mehta on Thursday 30 November 2023 13:54
I'm writing Perl code that takes a directory and its subdirectories and files, and then prints it to an Excel sheet using Excel::Writer::XLSX
. The issue I'm facing is some of my directories have numerical names like "1", "2.4".
Here's my code:
use Excel::Writer::XLSX;
my $workbook= Excel::Writer::XLSX->new( 'myExcel.xlsx' );
my $ws = $workbook->add_worksheet();
$path = "path_name";
{
$i= 0;
$j = 0;
sub dir_listing {
my ($root) = @_;
$root .= '/';
for my $f (glob "$root*")
{
if (-d $f)
{
$f =~ m/.*\/(.*)/;
$ws->write($i,$j,$1);
$j++;
dir_listing($f);
$j--;
}
if (-f $f)
{
$f =~ m/.*\/(.*)/;
$ws->write($i,$j,$1);
$i++;
}
}
}
}
dir_listing($path);
It's parsing through the numerical directories well and good, but it's not printing the directory name in the Excel sheet.
Argument "" isn't numeric in addition (+) at /home/priyansh.mehta/perl5/lib/perl5/Excel/Writer/XLSX/Worksheet.pm line 2510.
is the warning it shows after execution
I don't need the full path of the directory and files, only the names, hence the use of regex.
Published by /u/zhenyu_zeng on Thursday 30 November 2023 12:41
Hello,
On page 151 of Learning Perl: Making Easy Things Easy and Hard Things Possible, it says this code will cause warning
if ( $name =~ /(F\w+)|(P\w+)/ ) { # Fred or Pebbles? print "1: $1\n2: $2\n"; }
With warnings on, one of those capture variables will complain about an uninitialized value.
But in the test, it doesn't.
use warnings; use v5.34; my $name="hello"; if ($name=~/(F\w+)|(P\w+)/){ print "1:$1\n2:$2\n"; }
Everything is okay. Should this cause warning?
Published by laurent_r on Thursday 30 November 2023 04:22
These are some answers to the Week 245, 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 December 3, 2023 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.
You are given two arrays of languages and its popularity.
Write a script to sort the language based on popularity.
Example 1
Input: @lang = ('perl', 'c', 'python')
@popularity = (2, 1, 3)
Output: ('c', 'perl', 'python')
Example 2
Input: @lang = ('c++', 'haskell', 'java')
@popularity = (1, 3, 2)
Output: ('c++', 'java', 'haskell')
On reading the assignment, I initially thought for a minute or so that it would be quite easy to sort one array (@lang
) in accordance with the values of another one (@popularity
). But it immediately came to my mind that, in fact, you don't even need to actually sort anything. You can just use the second array (@popularity
) as an index slice for the first one (@lang
), so that we avoid the algorithmic complexity of a sort
procedure and return directly the languages in the proper order. The sort-lang
subroutine is thus a simple one-liner. Note that the input popularity is given with values starting at 1, whereas array or list indices start at 0, so we need the map {$_ - 1}
expression to convert popularities into array indices.
sub sort-lang (@lang, @pop) {
return ~ @lang[map {$_ - 1}, @pop];
}
my @tests =
{ lang => <perl c python>, pop => (2, 1, 3)},
{ lang => <c++ haskell java>, pop => (1, 3, 2)};
for @tests -> %test {
printf "%-20s", "%test<lang> => ";
say sort-lang %test<lang>, %test<pop>;
}
This program displays the following output:
$ raku ./sort-language.raku
perl c python => c perl python
c++ haskell java => c++ java haskell
This is a port to Perl of the Raku program above, and we are using array slices just like in the Raku implementation. Please refer to the previous section for any explanation.
use strict;
use warnings;
use feature 'say';
sub sort_lang {
my @lang = @{$_[0]};
my @pop = @{$_[1]};
return join " ", @lang[map {$_ - 1} @pop];
}
my @tests =
({ lang => [<perl c python>], pop => [2, 1, 3]},
{ lang => [<c++ haskell java>], pop => [1, 3, 2]});
for my $test (@tests) {
printf "%-22s", "@{$test->{lang}} => ";
say sort_lang $test->{lang}, $test->{pop};
}
This program displays the following output:
$ perl ./sort-language.pl
perl c python => c perl python
c++ haskell java => c++ java haskell
The next week Perl Weekly Challenge will start soon. If you want to participate in this challenge, please check https://perlweeklychallenge.org/ and make sure you answer the challenge before 23:59 BST (British summer time) on December 10, 2023. And, please, also spread the word about the Perl Weekly Challenge if you can.
Published by mauke on Thursday 30 November 2023 00:25
bisect: explicitly set diff path prefixes The patch code in Porting/bisect-runner.pl assumes `git show` will always display filenames with "a/..." and "b/..." prefixes. This is not necessarily the case. For example, the config settings diff.mnemonicPrefix and diff.noprefix can cause different prefixes or no prefixes at all to be used. In that case (e.g. after `git config --global diff.noprefix true`), bisect will halt like this: HEAD is now at 95388f2eb2 perlhist: Move 5.26.0 to another table to fix line length can't find file to patch at input line 24 Perhaps you used the wrong -p or --strip option? The text leading up to this was: -------------------------- |commit 46bfb3c49f22629a21d99ff2d02461a2a8a9aac4 |Author: Nicholas Clark <nick@ccl4.org> |Date: 2022-08-02 16:40:39 +0200 | | Configure should avoid looping infinitely repeating the same question | | Configure's helper function ./myread is intended to loop until it gets an | acceptable answer. For a couple of cases, an empty string is not acceptable | (eg 'Where is your C library?', if all automated attempts at answering this | have failed). In these cases, if Configure's standard input is /dev/null (or | closed), the shell read returns an empty string, and ./myread repeats the | question. | | Before this commit, it would loop infinitely (generating continuous terminal | output). With this commit, we add a retry counter - if it asks the same | question to many times, it aborts Configure. This means that unattended | ./Configure runs should now always terminate, as termination with an error | is better than spinning forever. | |diff --git Configure Configure |index 9d7fc39419..9d3b5f73b1 100755 |--- Configure |+++ Configure -------------------------- File to patch: ... which seems silly, seeing as how the filename is right there ("diff --git Configure Configure", "--- Configure", "+++ Configue") and yet bisect has to ask which file to patch ("it's Configure, duh!"). This commit tells git explicitly to use "a/" and "b/" as prefixes, which works no matter what the local config settings are.
Hello, I'm new to perl, I have some code which I have modified, but the newer version doesn't work when there isn't any 'xxx' in the input file: why is that?
Also is there a way to preserve ARGV when flushing the whole file using the diamond operator?
Older:
perl -WTe 'my $tmp = $ARGV[0]; my $x = do { local $/; <> } =~ /^\s?+'"'"'\s?+(\w+(\.\w+)?+)\s?+'"'"'/ ? do { $1 =~ s/\./\//g; $1 } : do { $tmp =~ /(.+)\./g; $1 }; print $x . "~"' file.txt
Newer (I can match regex on shift(), right?):
perl -WTe '&{ sub { my $x = do { local $/; <> } =~ /^\s?+'"'"'\s?+(\w+(\.\w+)?+)\s?+'"'"'/ ? do { $1 =~ s/\./\//g; $1 } : do { shift =~ /(.+)\./g; $1 }; print $x . "~" } }($ARGV[0])' file.txt
sorry for my bad english
Edit: sorry for all the stuff I forgot to write yesterday, I was really tired
Edit2: fixed typos
Published by bingos on Wednesday 29 November 2023 21:32
Module::CoreList updated for v5.34.3, v5.36.3 and v5.38.2
Published by /u/Grinnz on Wednesday 29 November 2023 18:25
Published on Wednesday 29 November 2023 16:57
cpan/Test-Simple - Update to version 1.302197 1.302197 2023-11-28 17:30:37-08:00 America/Los_Angeles - Add ability to attach timestamps to trace objects via api or env var 1.302196 2023-10-24 10:27:33-07:00 America/Los_Angeles - Fix #882 - Fix handling of VSTRING and LVALUE refs in is_deeply() #918 - Merge several doc fixes from mauke
Published on Tuesday 28 November 2023 10:30
In May of 2021, AWS released AppRunner to the public.
AWS App Runner is an AWS service that provides a fast, simple, and cost-effective way to deploy from source code or a container image directly to a scalable and secure web application in the AWS Cloud. You don’t need to learn new technologies, decide which compute service to use, or know how to provision and configure AWS resources.
App Runner connects directly to your code or image repository. It provides an automatic integration and delivery pipeline with fully managed operations, high performance, scalability, and security.
What makes AppRunner so compelling are these important features:
Back in 2012, I started a SaaS application (Treasurer’s Briefcase) for providing recordkeeping services for small non-profit organizations like PTOs, PTAs and Booster clubs. Back then, I cobbled together the infrastructure using the console, then started to explore CloudFormation and eventually re-architected everything using Terraform.
The application is essentially based on a LAMP stack - well sort of since I use a different templating web framework rather than PHP. The stack consists of an EC2 that hosts the Apache server, an EC2 that hosts some backend services, an ALB, a MySQL RDS instance and a VPC. There are a few other AWS services used like S3, SQS and EFS, but essentially the stack is relatively simple. Even so, provisioning all of that infrastructure using Terraform alone and creating a development, test, and production environments was a bit daunting but a great learning experience.
Starting with the original infrastructure, I reverse engineered it
using terraforming
and then
expanded it using terraform
.
The point being, it wasn’t necessarily easy to get it all right the first time. Keeping up with Terraform was also a challenge as it evolved over the years too. Moreover, maintaining infrastructure was just another task that provided no incremental value to the application. Time spent on that task took away from creating new features and enhancements that could provide more value to customers.
Enter AppRunner…with the promise of taking all of that work and chucking it out the window. Imagine creating a Docker container with your application and handing it to AWS and saying “host this for me, make it scalable, create and maintain an SSL certificate for me, create a CI/CD pipeline to redeploy the application when I make changes and make it cheap.” I’m in.
AppRunner has evolved over the years and has become much more mature. However, it still has some warts and pimples that might make you think twice about using it. Back in 2021 it was an interesting new service, an obvious evolutionary step from Fargate Tasks which provide some of the same features as AppRunner. Applications that utilized Fargate Tasks as the basis for running their containerized web applications still had to provision a VPC, load balancers, and manage scaling on their own. AppRunner bundles all of those capabilities and creates a compelling argument for moving Fargate based apps to AppRunner.
Prior to October 2022 AppRunner did not support the ability to access resources from within a VPC. That made it impossible for example, to use a non-publicly accessible RDS instance. With that addition in October of 2022, it was now possible to have a web application that could access your RDS in your VPC.
The fall of 2023 has seen several changes that make AppRunner even more compelling:
Change | Description | Date |
---|---|---|
Release: App Runner adds supports for AWS Europe (Paris), AWS Europe (London), and AWS Asia Pacific (Mumbai) Regions | AWS App Runner now supports AWS Europe (Paris), AWS Europe (London), and AWS Asia Pacific (Mumbai) Regions. | November 8, 2023 |
Release: App Runner adds dual stack support for incoming network traffic | AWS App Runner now adds dual stack support for incoming traffic through public endpoints. | November 2, 2023 |
Release: App Runner automates Route 53 domain configuration for your services | AWS App Runner automates Route 53 domain configuration for your App Runner service web applications. | October 4, 2023 |
Release: App Runner adds support for monorepo source-code based services | AWS App Runner now supports the deployment and maintenance for monorepo source-code based services. | September 26, 2023 |
Release: App Runner adds more features to auto scaling configuration management | AWS App Runner enhances auto scaling configuration management features. | September 22, 2023 |
Some of the limitations of AppRunner currently include:
The first limitation is a bit of show-stopper for more than a few web applications that might rely on mounted file systems to access assets or provide a stateful storage environment. For my application I use EFS to create session directories for logged in users. Using EFS I can be assured that each EC2 in my web farm accesses the user’s session regardless of which EC2 serves the request. Without EFS, I will be forced to re-think how to create a stateful storage environment for my web app. I could use S3 as storage (and probably should) but EFS provided a “quick-shot-on-goal” at the time.
The second limitation was just frustrating as associating a custom domain sort of kinda works. If I associate a domain managed by AWS (in the same account as my AppRunner application) then I was able to get the TLD to resolve and work as expected. AppRunner was able to associate my appliation to the domain AND provide an SSL certificate. It will redirect any http request to https. Unfortunately, I could not associate www sub-domain using the CLI as documented. In fact I could not even get the CLI to work without trying to enable the www sub-domain. Working with AWS support confirmed my experience and I still have a ticket pending with support on this issue. I’m confident that will be resolved soon(?) so it should not limit my ability to use this service in the future.
AppRunner is an exciting new service that will make application development and deployment seamless allowing developers to focus on the application not the infrastructure.
You can find the AppRunner roadmap and current issues here.
Published by Ron Savage on Monday 27 November 2023 09:20
See Perl.html
It's an example of the fabulous TiddlyWiki (tiddlywiki.com), so it's about 230,000 bytes.
Published by Gabor Szabo on Monday 27 November 2023 08:09
Originally published at Perl Weekly 644
Hi there,
Do you or your company sponsor Perl directly or indirectly?
As we all know, The Perl and Raku Foundation, is the parent organisation responsible for the development of Perl and Raku programming languages. They are also the single point of contact for any donations, whether individual or corporate. Without a doubt they are doing great service promoting Perl and Raku programming languages. I have personally seen how they support annual conferences around the globe.
Why am I talking about it today?
I run The Weekly Challenge project primarily focus on Perl and Raku but open to all programming languages. It was started on 25th March 2019. It has been going on un-interrupted ever since, thanks to the strong 350+ members of Team PWC. We were lucky enough to have solo sponsor, Perl Careers run by Peter Sergeant since July 2019 without break. Initially we had weekly prize sponsorship but later it was changed to monthly sponsorship. The best part was, I didn't have to move a finger to find the sponsor. Pete was generous enough to come forward and continued supporting the project for such a long time.
Is it time to look for new sponsor?
Well, we are not expensive to sponsor, honestly speaking. The prize money has been 50 USD since the beginning. Although I have been looking for new sponsors for sometime but never done anything about it. It is just not my cup of tea. Because of this, I put the code move on hold for such a long time. Ideally I wanted to move the code base to pure Perl solution instead of currently Hugo which is based on Go. I also wanted to move away from GitHub pages hosted solution to a proper hosted solution that we can manage ourself. I could have requested TPRF for financial help but again I am not competent enough to make formal request. As we are growing very fast every week, it is getting out of hand to manage the contributions by the team member. GitHub takes lot longer to process the data as some of the team member complained about it too. I wish we had our own repository to manage the contributions.
Any help or suggestions are most welcome.
Last but not the least, please do remember all those affected by the recent conflicts in your daily prayer. Enjoy rest of the newsletter.
--
Your editor: Mohammad S. Anwar.
Please checkout the weekly update by Perl Steering Council.
Bonus updates, two in a week, thank you Perl Steering Council.
Official announcement to submit papers for GPRW 2024.
Have you played with tainting on/off? Nice discussion how Perl behaves in each scenario.
Fun work if you are frequent blogger on bpo.
One of the many great CPAN Testers, Ron, shared the curated list of Perl modules.
The Weekly Challenge by Mohammad Anwar will help you step out of your comfort-zone. You can even win prize money of $50 Amazon voucher by participating in the weekly challenge. We pick one winner at the end of the month from among all of the contributors during the month. The monthly prize is kindly sponsored by Peter Sergeant of PerlCareers.
Welcome to a new week with a couple of fun tasks: "Sort Language" and "Largest of Three". If you are new to the weekly challenge, why not join us and have fun every week? For more information, please read the FAQ.
Enjoy a quick recap of last week's contributions by Team PWC dealing with the "Count Smaller" and "Group Hero" tasks in Perl and Raku. You will find plenty of solutions to keep you busy.
Clever use of map and grep to get the desired result. Well done and thanks for sharing.
Very compact and cute solutions. You must check it out. Thanks for your contributions.
Quality post with the most creative title every week. Keep it up great work.
So many variations and ideas. Plenty to keep you all busy. Thanks for sharing.
Thanks for reviewing CPAN module and sharing the details. Keep it up and well done.
Bloggng style is 2 way communication and I love it. Well done.
Raku one-liner, very impressive. Please keep us entertained every week.
In depth analysis and discussed solutions. Highly recommended.
Simple and straight forward solutions both in Perl and Raku, no gimmicks. Thank you.
Showing off the power of Raku built-in features. Perl is not far off either. Well balanced solutions. Keep it up great work.
Love the innocent comparison of Perl and Python. Well done.
Compact solutions in Raku and bonus in Python too. Thanks for sharing.
Use of CPAN module is clever move to get a compact solution. Well done.
Musical background to this week solution. Very interesting, keep it up.
Scalable and Do It Yourself styled solutions. Great effort, keep it up.
Clever approach to solve the task. You must checkout yourself.
Rust is very impressive, I must admit. You should check it out yourself. Highly recommended.
This is incredible, one-liner in Python. Simply the best. Thanks for sharing.
Great CPAN modules released last week;
StackOverflow Perl report.
A couple of entries sneaked in by Gabor.
The site checker is a new project of mine. If you have a web site, let me know what would you need to make this useful for you!
I've started to rewrite the code behind the Perl Maven and Code Maven sites to be a static site generator.
The Rust Maven web site contains all the new Rust-related articles and Rust-related slides. If you are interested in Rust sign up to my newsletter!
Our UK-based client is a global leader in the enterprise technology publishing industry, providing audiences worldwide with stimulating perspectives and unique news on enterprise tech that matters today and tomorrow. They are currently seeking a passionate and exceptional Perl programmer based in the Philippines to join their team.
Clever folks know that if you’re lucky, you can earn a living and have an adventure at the same time. Enter our international client: online trading is their game, and they’re looking for Perl People with passion, drive, and an appreciation for new experiences.
You joined the Perl Weekly to get weekly e-mails about the Perl programming language and related topics.
Want to see more? See the archives of all the issues.
Not yet subscribed to the newsletter? Join us free of charge!
(C) Copyright Gabor Szabo
The articles are copyright the respective authors.
Published on Sunday 26 November 2023 14:30
The examples used here are from the weekly challenge problem statement and demonstrate the working solution.
You are given an array of integers. Write a script to calculate the number of integers smaller than the integer at each index.
use v5.38;
sub count_smaller{
my @integers = @_;
my @integers_sorted = sort {$a <=> $b} @integers;
return map {
my $x = $_;
(grep { $integers[$x] == $integers_sorted[$_]} 0 .. @integers_sorted - 1)[0];
} 0 .. @integers - 1;
}
MAIN:{
say join q/, /, count_smaller qw/8 1 2 2 3/;
say join q/, /, count_smaller qw/6 5 4 8/;
say join q/, /, count_smaller qw/2 2 2/;
}
$ perl perl/ch-1.pl
4, 0, 1, 1, 3
2, 1, 0, 3
0, 0, 0
I'll admit this is a little convoluted. Since we already have a nested
loop with the map
and grep
this is not any more efficient than if I
had just searched and summed the smaller elements.
The idea here is to sort the array of integers and then for each element in the original array find it's position in the sorted array. The number of elements preceding the sought after element in the sorted list are the number of elements which are smaller than it.
This approach may have a performance benefit in the case of extremely large lists coupled with early termination of the inner loop.
You are given an array of integers representing the strength. Write a script to return the sum of the powers of all possible combinations; power is defined as the square of the largest number in a sequence, multiplied by the smallest.
use v5.38;
sub group_hero{
my @group = @_;
my $group_hero = 0;
do{
my $indices = $_;
my @hero = sort {$a <=> $b} @group[grep{vec($indices, $_, 1) == 1} 0 .. @group - 1];
$group_hero += ($hero[@hero - 1]**2 * $hero[0]);
} for 1 .. 2**@group - 1;
return $group_hero;
}
MAIN:{
say group_hero qw/2 1 4/;
}
$ perl perl/ch-2.pl
141
A core part of this problem is to compute the Power Set, set of all
subsets, of the original array. To do this we use the well known trick
of mapping the set bits of the numbers from 1 .. N^2
, where N
is the
size of the array, to the array indices.
@group[grep{vec($indices, $_, 1) == 1} 0 .. @group - 1]
examines which
bit within each number $_
in 1 .. 2**@group - 1
are set and then
uses them as the indices to @group
. The elements from within @group
that are found this way are then sorted to obtain the maximum and
minimum needed for the final calculation.
Each week Mohammad S. Anwar sends out The Weekly Challenge, a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. It's a great way for us all to practice some coding.
You are given an array of integers.
Write a script to calculate the number of integers smaller than the integer at each index.
This is a one-liner in Python
solution = [sum(1 for j in ints if j < i) for i in ints]
Breaking it down:
for i in ints
iterates through the supplied list, assigning each value to the variable i
.sum(1...)
will count the number of elements that satisfy the condition.for j in ints
creates an inner loop, assigning each value to the variable 'j'.j < i
will only count the elements where the value in the inner loop is lower than the outer loop.As Perl does not provide an easy way for double loops, I create a separate function to calculate the values less than a number, and then use the map function to iterate through each value.
sub less_than($i, $ints) {
return scalar( grep { $_ < $i } @$ints );
}
my @solution = map { less_than( $_, \@ints ) } @ints;
$ ./ch-1.py 8 1 2 2 3
4, 0, 1, 1, 3
$ ./ch-1.py 6 5 4 8
2, 1, 0, 3
$ ./ch-1.py 2 2 2
0, 0, 0
You are given an array of integers representing the strength.
Write a script to return the sum of the powers of all possible combinations; power is defined as the square of the largest number in a sequence, multiplied by the smallest.
For this task, I create a function called calculate_power
that returns the square of the largest number multiplied by the smallest number.
def calculate_power(numbers):
min_int = min(numbers)
max_int = max(numbers)
return max_int ** 2 * min_int
In the main function, I create a loop called length
which goes from 1 to the length of the supplied list. For each length
, I compute all combinations. Thankfully Python has a combination function in itertools.
for length in range(1, len(ints)+1):
power += sum(calculate_power(c) for c in combinations(ints, length))
Perl's combination function comes from the Algorithm::Combinatorics module.
foreach my $len ( 1 .. $#ints+1) {
my $iter = combinations(\@ints, $len);
while (my $c = $iter->next) {
$power += calculate_power($c);
}
}
$ ./ch-2.py 2 1 4
141
Published by Saif Ahmed on Sunday 26 November 2023 06:52
The October round of grant applications have been passed through the first stage of processing. Both have passed, and are awaiting funding clearance from our treasurer.
An interesting project trying to assist developers using AI was proposed by John Napiorkowski and Robert Grimes. This was aimed at feeding curated available quality bits of code into an AI model, and using an LLM to generate code. This has not yet visibly started but already has some enthusiastic following. Some practicalities are not specified, for example the IP of code and documentation used to train and that of the code generated, and cetainly those of us using GitHub are aware of the ethical complexities of allowing a helper AI using your code in other people's projects. Nor, for example, is the mitigation for potential to generate malicious code within the scope of this project. For these reasons, the Project has been split into two segments; a mini grant to kickstart the presence, analysis and initial coding process phase; this is then re-reviewed and if passed, a further production phase is supported.
Paul Evans is well known for a large number of Perl related contributions. Currently engaged in, amongst other things, a Object model that remains compatible with the core philosophies of Perl, bringing performance and simplicity into object cration into the Core. Perl has a large number of loosely compatible OOP paradigms; these are often powerful, hugely complex, heavy-weight, resource intensive frameworks, and therefore difficult to adopt into the core. For example Moose and Venus are superb super-OOPs, more powerful than those in many other languages. While these remain crucial to modern Perl application development, a model that has to be integrated into the core has different objectives, in terms of performance, robustness and abilitiy to not break existing applications. This challenge has been accepted by Paul and needs some support for this intensive task.
Grant applications are invited once again. Projects that are already in progress, that are open source, and those that benefit the Perl Community or the Perl Core may apply for additional support. There are three categories of Grants
See PERL CORE DEVELOPMENT FUND and RAKU DEVELOPMENT FUND pages
Read the HOW TO WRITE A PROPOSAL
Published by Unknown on Saturday 25 November 2023 21:32
These are the five most rated questions at Stack Overflow last week.
Between brackets: [question score / answers count]
Build date: 2023-11-25 20:24:18 GMT
Hi,
at 2024 FOSDEM there will be a Perl and Raku "Dev Room"
https://fosdem.org/2024/schedule/track/perl-raku/
Published by Perl Steering Council on Friday 24 November 2023 02:52
The PSC met today. In summary:
qt
strings, overload)Published by Perl Steering Council on Thursday 23 November 2023 22:15
This week we:
require
multiple times - seems not useful as compared to using do FILE
or the new load_module
builtinPublished by Oodler 577 on Thursday 23 November 2023 07:51
I've struggled with the syntax highlighting here on this blog. I really want to use this site and I will continue to do so.
After trying in vain to get some "auto" syntax highlighting here via the editor, I reached for an old trick I've used in the past. Generating HTML using some external service. After a quick Google search, I found https://tohtml.com/perl/. Given a block of Perl code, it'll generate HTML based syntax highlighting that one may add to their post. For example,
use Dispatch::Fu; # exports 'dispatch' and 'on', which are needed use Test::More tests => 1; my $INPUT = q{case1}; my $results = dispatch { my $input_str = shift; xdefault $input_str, q{do_default}; } $INPUT, on default => sub { 6 }, on case0 => sub { 0 }, on case1 => sub { 1 }, on case2 => sub { 2 }, on case3 => sub { 3 }, on case4 => sub { 4 }, on case5 => sub { 5 }; is $results, 1, q{POD example for xdefault works};
It has been suggested to use an approach that uses "pre" and "code" HTML, and results in the following:
use Dispatch::Fu; # exports 'dispatch' and 'on', which are needed
use Test::More tests => 1;
my $INPUT = q{case1};
my $results = dispatch {
my $inputstr = shift;
xdefault $inputstr, q{do_default};
}
$INPUT,
on default => sub { 6 },
on case0 => sub { 0 },
on case1 => sub { 1 },
on case2 => sub { 2 },
on case3 => sub { 3 },
on case4 => sub { 4 },
on case5 => sub { 5 };
is $results, 1, q{POD example for xdefault works};
However this is not going to satisfy what I want to see. Some notes with using https://tohtml.com/perl/:
The last thing I want to do is bag on this site. I prefer to use blogs.perl.org over anything else, I just think we need to try harder to provide properly colored code examples.
Do you have a method that works internally or a better suggestion for creating properly highlighted code blocks at blogs.perl.org?
Many have suggested using dev.to or some other site. As much as I appreciate that suggestion, I am trying to solve an issue here so that we can improve the experience by both readers and authors. Please comment below.
Thanks to the folks who helped me sort this out on the TPRF Slack.
Cheers!
Published by Bob Lied on Tuesday 21 November 2023 18:04
One pass over sorted data is a better strategy than searching through random data.
Perl Weekly Challenge 244, Task 1, Count Smaller asks us to categorize data for its relative values:
You are given an array of integers. Write a
script to calculate the number of integers
smaller than the integer at each index.
Input:
@int = (8, 1, 2, 2, 3)
Output:(4, 0, 1, 1, 3)
For index = 0, count of elements less than 8 is 4.
For index = 1, count of elements less than 1 is 0.
For index = 2, count of elements less than 2 is 1.
For index = 3, count of elements less than 2 is 1.
For index = 4, count of elements less than 3 is 3.
Input:
@int = (6, 5, 4, 8)
Output:(2, 1, 0, 3)
Input:
@int = (2, 2, 2)
Output:(0, 0, 0)
The first idea, as usual, is brute force. For every element in the array, scan the array for values that are less than that. An optimization that immediately occurs to me is that the scan for smaller values would be easier if the numbers are sorted; we can quit early and don't have to scan the entire list every time.
sub countSmaller_A($nums)
{
my @sorted = sort { $a <=> $b } $nums->@*;
my @smaller = ();
for my $i ( $nums->@* )
{
my $count = 0;
for my $j ( @sorted )
{
last if $j >= $i;
$count++
}
push @smaller, $count;
}
return \@smaller;
}
Searching in a sorted list has an optimization. We could find the index of the first element in @sorted
that is greater than $i
using binary search (or, more realistically, using List::Utils::bsearch_index
because my odds of getting a binary search algorithm right are slim). Maybe I'll come back to this, but this is basically an O(n^2) algorithm, so there are probably better ideas to explore.
The second approach is to count how many times each value occurs, saving a frequency table. Then select from that table all the lesser numbers and add them up. This is a bit of a Perl tour-de-force, using array operations up the wazoo. The code is compact, but the complexity might not be worth it.
sub countSmaller_B($nums)
{
use List::Util qw/sum0/;
my %freq;
$freq{$_}++ for $nums->@*;
return [ map { my $i = $_; sum0 @freq{ grep { $_ < $i } keys %freq } } $nums->@* ];
}
Building the frequency table is relatively obvious, but what's going on in that last line?
return [ ... ]
-- the answer is going to be an array reference to the list of numbersreturn [ map { my $i = $_; ... } $nums->@*
] -- the list of numbers is going to be generated by mapping each of the original numbers to its count of smaller numbers. Each of the original numbers is going to be assigned to $i
while we're doing the transformationgrep { $_ < $i } keys %freq
-- we're going to select all keys from the frequency table %freq
where the key is less than the number we're looking at@freq{ grep...}
-- Using the list of keys from the grep
, take a hash slice from the %freq
table. This will give us the counts of each value less than $i
.sum0 @freq...
-- The sum0
function adds up the values in an array, defaulting to 0 if the array is empty.Let's return for a moment to that sorted array we built back in Idea 1. Once the array is sorted, it's pretty easy to find all the smaller numbers -- it's a monotonically increasing sequence as we scan from left to right.
There are two complications: repeated values, and the fact that the answer has to be in the same order as the original array. Hashes for caches and hash slices are going to come to our rescue.
sub countSmaller_C($nums)
{
my @sorted = sort { $a <=> $b } $nums->@*;
my %smaller;
my $lessCount = 0;
while ( defined(my $i = shift @sorted) )
{
if ( ! exists $smaller{$i} )
{
$smaller{$i} = $lessCount;
}
$lessCount++
}
return [ @smaller{$nums->@*} ];
}
The first thing we do is take the hit of doing the sort, on the premise that we're going to get that performance back with a simpler search loop.
The %smaller
variable is a hash that is going to contain our answer, but in an arbitrary order. We will un-arbitrary it at the end with a hash slice that uses the original array for keys -- that will solve our ordering problem.
The $lessCount
variable is an accumulator that will count up the number of smaller values as we pass over the sorted array.
The while
loop will take elements off the sorted array from left to right. We saw last week that shifting elements off the array can be more efficient than using array indexing. A quick note: the test has to include defined
because there could be a zero in the data, and that would test as false.
Within the loop, we use the %smaller
array as a cache for values we've already seen. That solves our repeated-values problem.
This is only an exhibition; no wagering, please. As I've been doing for the past week, I brought out the Benchmark
module for some simple comparison.
sub runBenchmark($repeat)
{
use Benchmark qw/cmpthese/;
my @data = map { int(rand(100)) } 1..100;
cmpthese($repeat, {
"simple " => sub { countSmaller_A(\@data) },
"frequency" => sub { countSmaller_B(\@data) },
"one pass " => sub { countSmaller_C(\@data) },
});
}
The benchmark generates some bigger data than task examples, and then runs the functions thousands of times to get something like a statistically valid result.
And here's the big reveal, sorted from slowest to fastest:
Rate frequency simple one pass
frequency 1339/s -- -63% -95%
simple 3647/s 172% -- -88%
one pass 29268/s 2085% 702% --
First of all, those compact array operations in Idea 2 look cute, but there's a lot of data access going on underneath. We were better off with using more readable loops from Idea 1.
But, wow! Look at the one pass solution! Literally ten times faster. Better algorithms beat micro-optimizations.
Published by Makoto Nozaki on Monday 20 November 2023 22:42
Get ready for an unforgettable experience at one of the biggest Perl events in the world - YAPC::Hiroshima, organized by the Japan Perl Association.
📅 Event details
🚀 Why attend YAPC::HIroshima 2024?
🎟️ Registration is Now Open
Reserve your spot at YAPC::Hiroshima 2024 by registering today. General admission is JPY 10,000 (approximately USD 70), with the option for individual sponsorship (additional JPY 10,000) and student discount (free).
Note all talks will be conducted in Japanese.
🗾 About Japan Perl Foundation
Japan Perl Association (JPA) is a non-profit organization based in Japan that focuses on promoting and supporting the Perl programming language within the country. The association is actively involved in organizing Perl events, conferences, and workshops targeting beginners (Perl Entrance).
Published by Bob Lied on Monday 20 November 2023 15:16
TLDR: sub afterinit { push @DB::typeahead, "o compactDump=1" }
When I use the Perl debugger, I usually want the compactDump
option turned on. For reasons (?), I have never been able to set this option from the ~/.perldb
file. It should be possible to set options by using lines like
...
parse_options("HistSize=100");
parse_options("compactDump=1");
...
but when I try that with compactDump
, starting up the debugger gives me a lot of unsightly warnings:
[~/]$ perl -d -wE 'say "what"'
Variable "$frame" is not imported at (eval 6)[/Users/lied/perl5/perlbrew/perls/perl-5.38.0/lib/5.38.0/perl5db.pl:7578] line 2.
Variable "$doret" is not imported at (eval 6)[/Users/lied/perl5/perlbrew/perls/perl-5.38.0/lib/5.38.0/perl5db.pl:7578] line 3.
perldb: couldn't parse ./.perldb: Global symbol "$frame" requires explicit package name (did you forget to declare "my $frame"?) at (eval 6)[/Users/lied/perl5/perlbrew/perls/perl-5.38.0/lib/5.38.0/perl5db.pl:7578] line 2.
Global symbol "$doret" requires explicit package name (did you forget to declare "my $doret"?) at (eval 6)[/Users/lied/perl5/perlbrew/perls/perl-5.38.0/lib/5.38.0/perl5db.pl:7578] line 3.
A close reading of some Stack Overflow articles and the perldoc perldebug
documentation finally gave me a workaround. The following, added to ~/.perldb
, will enable compactDump
without the noise:
sub afterinit { push @DB::typeahead, "o compactDump=1" }
This assumes that we are using GNU readline
, which, of course we are.
The examples used here are from the weekly challenge problem statement and demonstrate the working solution.
You are given an array of integers. Write a script to return the number of reverse pairs in the given array.
use v5.38;
sub reverse_pairs{
my @integers = @_;
my @reverse_pairs;
do{
my $i = $_;
do{
my $j = $_;
push @reverse_pairs, [$i, $j] if $integers[$i] > $integers[$j] + $integers[$j];
} for $i + 1 .. @integers - 1;
} for 0 .. @integers - 1;
return 0 + @reverse_pairs;
}
MAIN:{
say reverse_pairs 1, 3, 2, 3, 1;
say reverse_pairs 2, 4, 3, 5, 1;
}
$ perl perl/ch-1.pl
2
3
A reverse pair is a pair (i, j) where:
a) 0 <= i < j < nums.length
and
b) nums[i] > 2 * nums[j].
I've been on a bit of a recursion kick recently, but I didn't have the appetite for it this week. A nested loop and we're done!
You are given an array of positive integers (>=1). Write a script to return the floor sum.
use v5.38;
use POSIX;
sub floor_sum{
my @integers = @_;
my $floor_sum;
do{
my $i = $_;
do{
my $j = $_;
$floor_sum += floor($integers[$i] / $integers[$j]);
} for 0 .. @integers - 1;
} for 0 .. @integers - 1;
return $floor_sum;
}
MAIN:{
say floor_sum 2, 5, 9;
say floor_sum 7, 7, 7, 7, 7, 7, 7;
}
$ perl perl/ch-2.pl
10
49
See above comment about not being as recursive this week!
Published by Unknown on Saturday 18 November 2023 22:03
This is the weekly favourites list of CPAN distributions. Votes count: 41
This week there isn't any remarkable distribution
Build date: 2023/11/18 21:00:04 GMT
Clicked for first time:
Increasing its reputation:
Published by Khun Yee Fung, Ph.D. on Saturday 18 November 2023 20:18
Published by Amber Krawczyk on Friday 17 November 2023 14:01
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 TPRF's FOSDEM 2024 dev room.
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 $300 to assist with the cost of attending.
To apply for a FOSDEM mini grant, please send a completed application to fosdem2024-grants@perlfoundation.org or send it to Amber Krawczyk on the TPRF slack.
If you have questions, please join our fosdem slack channel, leave a comment below, or send a message to hello@perlfoundation.org
Published by Amber Krawczyk on Tuesday 14 November 2023 22:48
==================================
The Perl and Raku Foundation is thrilled to announce that the FOSDEM organising team has accepted our proposal to set up a DevRoom on Saturday, February 3rd 2024. It has been quite a few years since the last Perl DevRoom at FOSDEM. Historically, they have always been well attended and packed.
Since last time, a lot has happened, and TPRF is excited to help create this venue for sharing news with developers from Europe and across the globe. Many FOSDEM visitors have a background using Perl, but may have missed out on recent developments. Larry Wall himself was a guest speaker at FOSDEM in 2015 to announce Perl 6, which was later renamed to Raku. Much has happened since then, and there is lots to share!
TPRF would like to offer contributors to Perl, Raku, their ecosystems and modules, or any other FOSS projects the opportunity to participate at this exciting annual event in Brussels. The TPRF-FOSDEM organisers are specifically looking for anyone with a compelling story to share about their Open Source project that has a strong background in Raku or Perl.
Do you have something fascinating or new to share with the Perl and Raku communities?
Then do not hesitate to submit your presentation proposal. Visit the FOSDEM 2024 Pretalx website and fill in the form. There is a limited availability for speakers to give a 20 minute engaging presentation.
Deadline for submissions is December 1st, 2023.
FOSDEM is a two day, free event for software developers to meet, share ideas, and collaborate. Every year, thousands of developers of free and open source software from all over the world gather at this annual event in Brussels.
FOSDEM 2024 will take place on Saturday 3 and Sunday 4 February 2024. It will be an in-person event at the ULB Solbosch Campus, Brussels, Belgium, Europe.
TPRF is dedicated to the advancement of the Perl and Raku programming languages, through open discussions, collaboration, design, and code. The Perl and Raku Foundation's desire is to build a strong, healthy and sustainable language ecosystem and community. The TPRF grant programs help fund development of open source projects to benefit Perl, Raku and the broader community. The foundation helps to sponsor many events, worldwide, each year. Open source development depends on events like FOSDEM, which allow developers to come together in person and share ideas, code, and have fun.
The Perl and Raku Foundation website Call for Participation 2024.md Displaying Call for Participation 2024.md.
The examples used here are from the weekly challenge problem statement and demonstrate the working solution.
You are given two arrays of integers. Write a script to find out the missing members in each other arrays.
use v5.38;
use boolean;
use Data::Dump q/pp/;
sub missing_members{
my @r;
my($a0, $a1) = @_;
my $missing0 = [];
missing_members_r([@{$a0}], [@{$a1}], $missing0);
my $missing1 = [];
missing_members_r([@{$a1}], [@{$a0}], $missing1);
push @r, $missing0 if @{$missing0} > 0;
push @r, $missing1 if @{$missing1} > 0;
return @r;
}
sub missing_members_r{
my($a0, $a1, $missing, $seen) = @_;
$seen = [] if !defined($seen);
my $x = shift @{$a0};
push @{$missing}, $x if missing_r($x, [@{$a1}]) && !seen_r($x, $seen);
push @{$seen}, $x;
missing_members_r($a0, $a1, $missing, $seen) if @{$a0} > 0;
}
sub missing_r{
my($x, $a0) = @_;
return true if @{$a0} == 0;
if(@{$a0}){
my $y = shift @{$a0};
if($x == $y){
return false;
}
}
return missing_r($x, $a0);
}
sub seen_r{
my($x, $seen) = @_;
return false if @{$seen} == 0;
my $y = shift @{$seen};
if($x == $y){
return true;
}
return seen_r($x, $seen);
}
MAIN:{
my @array1 = (1, 2, 3);
my @array2 = (2, 4, 6);
say pp missing_members \@array1, \@array2;
@array1 = (1, 2, 3, 3);
@array2 = (1, 1, 2, 2);
say pp missing_members \@array1, \@array2;
}
$ perl perl/ch-1.pl
([1, 3], [4, 6])
[3]
So, yeah, this could just be a nice quick use of grep
, but where is the fun in that!?!?
Just looping over the arrays is not that exciting of an alternative, what other options
are there? I know, how about a whole lot of recursion! That was pretty much my thought
process here.
Really, all this code is doing is looping over the two arrays and looking for which
elements are not contained in each. The looping, such as it is, happens recursively in
missing_members_r()
and missing_r()
. Duplicates are possible and we avoid these, again
recursively, using seen_r()
rather than, say, grep
or hash keys.
You are given n x n binary matrix. Write a script to flip the given matrix as below.
use v5.38;
use Data::Dump q/pp/;
sub flip_matrix{
return map {
my $row = $_;
[map {~$_ & 1} reverse @{$row}]
} @_;
}
MAIN:{
my @matrix = ([1, 1, 0], [1, 0, 1], [0, 0, 0]);
say pp flip_matrix @matrix;
@matrix = ([1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]);
say pp flip_matrix @matrix;
}
$ perl perl/ch-2.pl
([1, 0, 0], [0, 1, 0], [1, 1, 1])
([1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1], [1, 0, 1, 0])
After all the recursive exitment in part 1 of this week's challenge I just went with a
quick nested map
for part 2.
Published by Unknown on Saturday 11 November 2023 22:00
Every development project ultimately has a goal of providing some kind of value to the organization that has decided to initiate a software development project.
The bottom line of any software development project is the bottom line. Does the cost of the project AND the maintenance of the project create a profit?
I know what you are thinking. Not all software applications are designed to produce profit. Untrue. Even applications we call “internal” create value or contribute to the creation of value.
Let’s talk about and characterize failure first. Because its much easier to define (as anyone who has had the misfortune of working with a product development team that cannot define “done” knows). And I’ve been told that that most software development projects fail.
The project is canceled.
This is the “first order broke” condition of projects. It took too long, it went over budget and looked to continue to be a money pit (someone understood the fallacy of sunk costs), the environment changed making the application moot or a new CEO decided to replace all internal applications with some SaaS, PaaS, or his own pet project.
The application was launched and did not meet the goals of the project.
This can mean a lot of things: the project does not solve enough of the business problems to justify the continued cost of maintenance. Or perhaps the application did not generate enough revenue to justify its existence because of poor market acceptance. People just hate using it.
The project is in use, people use it, but the ROI is too far in the future or perhaps indeterminate.
The project becomes a drag on the organization. No one wants to pull the plug because they have no alternative (or believe they don’t). There’s no appetite to rewrite, refactor or reimagine the application. It becomes a huge boat anchor that a handful of engineers keep running by kicking it in the ass whenever it stalls.
The project launches on time and under budget.
Keep in mind that this is (mostly) a necesasry, but insufficient condition for success. Yes, there are some successful projects that are over budget or late, but its sort of like starting Monopoly owing everyone money. You need to catch up and catch up fast.
The application completely solves the business problem.
Again, a necessary but insufficient condition for success. If the application is difficult to maintain and requires constant attention that costs more than it saves or produces, it’s not a success.
The application just works
…and is a critical component in a complex workflow - without it nothing else would - its cost to develop and maintain is easily justified by the the nature of its job. It successfully completes its mission every single day.
Oh yeah, Agile. I read articles about Agile and people’s experience with it all the time. I suspect most opinions are based on few data points and mostly from one person’s negative (or rarely positive) experience with Agile. My opinions (and that’s all they are…YMMV) are based on working with some fairly large clients that I am not at liberty to divulge. One FANG, one Fortune 50 company, one major manufacturer of phones and multiple companies with more than 5000 employees. I’m not opining based on one ride on the merry-go-round. I’m the kind of person that always believes that I just don’t get it, and I need to learn more, read more and accept more to overcome my ignorance and lack of experience. It’s a viewpoint that has allowed me to grow in my career and learn a lot of very useful things that have conspired to make me, if not wealthy, not concerned about money.
I am now having a lot fun going back to my roots of being a software developer. While I have been on the management side of projects employing the Agile process I am now in the belly of the beast. It smells bad, feels wrong and kills productivity. But, again, YMMV.
Product Owners - All “product owners” are not created equal. They have varying degrees of understanding of their own domain. Some even believe developers have ESP. To be fair, some expect developers (and rightly so) to “ask questions”. The problem is, what happens when the developer does not understand the domain. What questions should they ask? They are clueless.
Product owners should assume nothing (in my opinion) and determine the level of domain expertise developers have. It is their responsibility to make that assessment - if they don’t they must be explicit with requirements, otherwise you’ll almost certainly end up with a project or feature that does not meet your needs.
So, here’s the bottom line. Any idea worth something greater than 0 that also has a wee bit of marketing behind it quickly becomes an opportunity for gypsies, tramps and thieves to exploit the ignorant masses. Take Christianity for example. Need I say more? Agile has become the Chrisitianity of corporate America. No one dare mention that is doesn’t solve our problems or make us feel any better. Fuck Agile, the ceremonies, the training, the roles the practice…it is the most unproductive enviroment one can devise for developing software. Look it up…Bill Gates wrote an entire BASIC interpreter and shoved it into 4K of a ROM. He then worked on a 32K version that was essentially a complete OS. He didn’t need Agile to do that.
So, let’s be clear. Agile is social engineering. An attempt to organize human beings in order to create something that no one of them could do alone (or so it goes). Somehow I don’t think Agile works. Some will say, yeah, well not every project should use Agile. Yes, that’s true, but the sad fact is that corporate America is not nuanced. They are binary. They want single solutions to complex problems and do not want to hear…it depends. And so they consume the entire bottle of aspirin.
There will be a day when people look back at the unproductive, waste and utter insansity that is “Agile”. They will marvel at the way that a single, possibly good idea for some things, was transformed into a dogma that haunted software development for a decade.
I’m hopeful however that really smart companies know that instituting things like Agile are the bellweather of their demise. They will avoid trying to fit round pegs into square holes. They will embrace the idea that you can plan things properly, but plans can change without embracing a chaotic, highly disorganized process that actually masquerades as a structured protocol.
You have been warned. When some consultant you hire to justify the outsourcing of your development team says that they can replace your current processes with an Agile team from Elbonia and a scrum master from Bumblefuck…be afraid…be very afraid. There is no free lunch.
One final thought…why is software development so hard? And why do we struggle so to create applications?
It’s not a hard question actually. The goal of software development is to codify a solution to a problem. But first…and here is the reveal…you have to define the problem. That is, in and of itself the most difficult thing in the development process. Missed requirements are, in my experience, the biggest reason for “re-work”. Note I did not say “bugs” or “defects”. Most maintenance on systems is because of missed requirements, not because programmers make mistakes. Oh, for sure, they do. But really? Think. Look back at your tickets and do a root cause analysis.
There are other reasons software development is hard. First, people do not communicate well. The do not communicate precisely and they do not communicate accurately. Next, the tools to express the solutions to our problems are complex and incomplete. Better ingredients make better pizzas. Papa Johns!
Okay, I have to wrap this up…Agile sucks. I hate Agile. I want to mute myself when I’m in stand-ups just to say every day “Oh, I was on mute.” and torture everyone that thinks this ceremony is useful.
Oh,I’m having issues with my internet so I may have to drop soon….open the pod bay doors Hal?
Published by Staney Joseph ️ on Monday 06 November 2023 03:22
Perl, a high-level, general-purpose, interpreted, dynamic programming language, has been an industry staple since its creation in 1987…
The examples used here are from the weekly challenge problem statement and demonstrate the working solution.
You are given an array (3 or more members) of integers in increasing order and a positive integer. Write a script to find out the number of unique Arithmetic Triplets satisfying the given rules.
use v5.38;
sub arithmetic_triplets{
my $counter = 0;
my $difference = shift;
arithmetic_triplets_r($difference, \$counter, [@_[0 .. @_ -1]], [@_[1 .. @_ -1]], [@_[2 .. @_ -1]]);
return $counter;
}
sub arithmetic_triplets_r{
my $difference = $_[0];
my $counter = $_[1];
my @i = @{$_[2]};
my @j = @{$_[3]};
my @k = @{$_[4]};
if(@i > 0 && @j > 0 && @k > 0){
$$counter++ if $j[0] - $i[0] == $difference && $k[0] - $j[0] == $difference;
arithmetic_triplets_r($difference, $counter, [@i], [@j], [@k[1 .. @k - 1]]);
}
elsif(@i > 0 && @k == 0 && @j > 0){
arithmetic_triplets_r($difference, $counter, [@i], [@j[1 .. @j - 1]], [@j[2 .. @j - 1]]);
}
elsif(@i > 0 && @k == 0 && @j == 0){
arithmetic_triplets_r($difference, $counter, [@i[1 .. @i - 1]], [@i[2 .. @i - 1]], [@i[3 .. @i - 1]]);
}
}
MAIN:{
my $difference;
$difference = 3;
say arithmetic_triplets $difference, 0, 1, 4, 6, 7, 10;
$difference = 2;
say arithmetic_triplets $difference, 4, 5, 6, 7, 8, 9;
}
$ perl perl/ch-1.pl
2
2
The rules for arithmetic triples are a) i < j < k b) nums[j] - nums[i] == diff and c) nums[k] - nums[j] == diff, where diff is a provided parameter. The code above implements these rules somewhat in the obvious way, looping thricely over the list, but recursively.
You are given an array of unique positive integers greater than 2. Write a script to sort them in ascending order of the count of their prime factors, tie-breaking by ascending value.
use v5.38;
sub prime_factor{
my $x = shift(@_);
my @factors;
for (my $y = 2; $y <= $x; $y++){
next if $x % $y;
$x /= $y;
push @factors, $y;
redo;
}
return @factors;
}
sub prime_order{
my %factor_i = map{($_, 0 + prime_factor($_))} @_;
my $factor_sorter = sub{
my $c = $factor_i{$a} <=> $factor_i{$b};
return $c unless !$c;
return $a <=> $b;
};
return sort $factor_sorter @_;
}
MAIN:{
say join q/, /, prime_order 11, 8, 27, 4;
}
$ perl perl/ch-2.pl
11, 4, 8, 27
This code borrows from two previous challenges: The prime factor code has been used several times, but in this case I referred to the Attractive Number challenge from TWC 041. The sorting is a variant of the frequency sort from TWC 233. If you write enough code you don't need GitHub Copilot, you can just re-use your own work!
Published by alh on Thursday 02 November 2023 14:02
Tony writes:
``` [Hours] [Activity] 2023/09/04 Monday 0.13 github notifications 0.40 #21421 fix some noise from G_USEHINTS tests 1.03 #21419 thinking, comment 1.55 #21449 review and approve 1.02 look into AIX smoke failures, find at least one problem,
4.13
2023/09/05 Tuesday 0.38 email George Greer about mingw smoke failures 1.75 look into fedora smoke failure, reproduce, just #20812 0.27 #21451 apply to blead and perldelta
3.10
2023/09/06 Wednesday 0.60 #20812 some changes, push for CI 0.05 #21454 review and approve 0.10 #21405 review and approve 1.00 #21367 review, research, approve and comment 0.47 security list discussion: research, comment 0.10 #21418 review and apply to blead 0.87 #21422 review and comment
3.57
2023/09/07 Thursday 0.90 #20812 updates 0.17 #21442 review updates and approve 1.40 #21426 review and approve 0.23 #21404 review and comment 0.40 security list follow up
4.12
2023/09/11 Monday 0.78 security list discussion, research, updates 0.47 #21367 apply to blead, perldelta 0.17 #21463 re-check, apply to blead 0.75 #21419 review new changes, comment 0.37 EU::CB: follow up on mail from AMBS to p5p
4.32
2023/09/12 Tuesday 0.23 #21419 review latest changes and approve 1.13 #21467 review latest changes
1.41
2023/09/13 Wednesday 0.82 #21450 review, research and comment 0.35 #21469 review and approve 1.03 #21468 review, look at smoke results, testing and comment 0.27 #21470 review and approve 0.18 #21471 review and approve 0.10 #21472 review and approve 0.12 #21474 review and approve 0.25 #21475 review and approve 0.37 #21468 testing and comment
5.69
2023/09/14 Thursday 0.37 github notifications 1.77 #19370 work out failing test, more testing, minor fixes, push for CI
3.11
2023/09/15 Friday 0.22 #21457 apply to blead, perldelta
0.57
2023/09/18 Monday 0.60 #21488 review, comments 0.73 #21481 review, comment 1.90 #21458 review discussion, review PR 21484, testing, comments 0.25 #21476 review and approve 0.20 #21482 review and approve 0.57 #19370 check CI results, make PR 21489
4.65
2023/09/19 Tuesday 0.68 #21484 more testing, comment 1.23 #21490 look over comment, research and add an additional commit 0.25 #21403 review, research and approve 0.12 #21429 review and approve 1.53 #21486 try working up an op_free() inline patch, try
3.81
2023/09/20 Wednesday 0.33 #21481 review and approve 0.10 #21488 review and approve 0.57 #21473 review, testing and comment 1.90 #16971 work up a fix for the basic issue, try to get other similar split()s to crash 0.17 #16971 clean up, push for CI
3.52
2023/09/21 Thursday 0.50 #21498 struggle with github’s diff between latin-1 and utf- 8 encoded versions of file and comment 0.18 #21473 follow-up comment 2.23 #21458 try a clever approach, and get the ticket regression tests to pass, but unfortunately other tests fail 2.05 #21458 try the boring approach, add more tests, testing,
4.96
2023/09/25 Monday 1.05 #20917 rebase and push for CI 0.10 #21490 apply to blead 0.10 #21503 apply to blead 0.12 #21489 apply to blead 0.93 #20810 testing and comment 0.85 #21473 no scanf: re-work S_parse_version and push for CI 0.70 perldelta for applied patches
4.13
2023/09/26 Tuesday 1.80 #21516 fix an issue which ended up not being what I though, polish and push for CI 1.27 #21513 review and comments 0.55 security list research
3.94
2023/09/27 Wednesday 0.10 #21516 apply to blead 0.75 #21522 review failing tests, open downstream ticket, comment 0.90 #21523 review code, consider fixes
3.30
2023/09/28 Thursday 1.40 security issue admin, review, testing 0.35 more security issue admin 0.52 #21525 review and approve 0.10 #21526 review and approve
2.59
2023/09/29 Friday
1.22
Which I calculate is 62.14 hours.
Approximately 52 tickets were reviewed or worked on, and 10 patches were applied. ```