The following programs, one in Javascript, and the other in Perl, are supposed to perform the same task, they have the same input data. However, the output is different. The problem originated in the JS being used on the client side, sending a POST request to an app on the server side, written in Perl. The Perl program failed to decrypt with no obvious reason why. Analysing it I arrived to the conclusion that the libraries, in the two different programming languages, were behaving differently. So I wrote the client side in Perl to prove the point. The results are below.

const CryptoJS = require('crypto-js');

function logBytes(description, wordArray) {
    const bytes = CryptoJS.enc.Hex.stringify(wordArray);
    console.log(description, bytes);
}

function encrypt(key32, iv16, data) {
    const key = CryptoJS.enc.Hex.parse(key32);
    const iv = CryptoJS.enc.Hex.parse(iv16);
    const utf8data = CryptoJS.enc.Utf8.parse(data);

    // Log data and byte arrays
    console.log("Data: " + data);
    logBytes("Key Bytes:", key);
    logBytes("IV Bytes:", iv);
    logBytes("Data Bytes:", utf8data);

    const encrypted = CryptoJS.AES.encrypt(utf8data, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });

    console.log("Encrypted (Base64):", encrypted.toString());
}

const data = "myemail@myserver.com";
const key32 = "9d066ab6dc74593bbcef0876b4f7c00bada3acce6134fc64fa31a2cf995a39dd";
const iv16 = "9b2b9bdb4af5357cd78a8a2257c51a7f";
encrypt(key32, iv16, data);

output:

 % node test.js
Data: myemail@myserver.com
Key Bytes: 9d066ab6dc74593bbcef0876b4f7c00bada3acce6134fc64fa31a2cf995a39dd
IV Bytes: 9b2b9bdb4af5357cd78a8a2257c51a7f
Data Bytes: 6d79656d61696c406d797365727665722e636f6d
Encrypted (Base64): iit+mjBnWsMrMkJp63hpRmsCZgIxZ4FPZQId35qv12s=
#!/usr/bin/perl

use strict;
use warnings;

use MIME::Base64;
use Crypt::OpenSSL::AES;

sub logMessage {
  my ($message) = @_;
  print "$message\n";
}

sub logBytes {
    my ($description, $bytes) = @_;
    my $hex = unpack('H*', $bytes);
    logMessage("$description: $hex");
}

sub encrypt {
    my ($key32, $iv16, $data) = @_;

    my $key = pack('H*', $key32);
    my $iv = pack('H*', $iv16);

    # Log data and byte arrays
    logMessage("Data: $data");
    logBytes("Key Bytes", $key);
    logBytes("IV Bytes", $iv);
    logBytes("Data Bytes", $data);

    my $cipher = Crypt::OpenSSL::AES->new($key);

    my $block_size = 16;
    my $padding = $block_size - (length($data) % $block_size);
    $data .= chr($padding) x $padding;

    my $encrypted = $cipher->encrypt($data);

    my $encrypted_base64 = encode_base64($encrypted, "");

    logMessage("Encrypted (Base64): $encrypted_base64");
}

sub main {
  my $data = "myemail\@myserver.com";
  my $key32 = '9d066ab6dc74593bbcef0876b4f7c00bada3acce6134fc64fa31a2cf995a39dd';
  my $iv16 = '9b2b9bdb4af5357cd78a8a2257c51a7f';
  encrypt($key32, $iv16, $data);
}

main();
exit (0);

output

% ./test.pm  
Data: myemail@myserver.com
Key Bytes: 9d066ab6dc74593bbcef0876b4f7c00bada3acce6134fc64fa31a2cf995a39dd
IV Bytes: 9b2b9bdb4af5357cd78a8a2257c51a7f
Data Bytes: 6d79656d61696c406d797365727665722e636f6d
Encrypted (Base64): rk7JgOwsb7atyvEIXVNQkexbx5SYzufE05LZAoqtZGk=
Versions:

Perl:
Crypt::OpenSSL::AES version: 0.19
MIME::Base64 version: 3.16

JS:
crypto-js@4.2.0

how to get regex colored in perl debugger session [closed]

Perl questions on StackOverflow

Published by Vincent Santana on Thursday 18 April 2024 16:31

How can I display regular expressions in special color while in Perl debugger session? I've searched online extensively, including Google and various forums, but haven't found a solution that works. Any suggestions or insights would be greatly appreciated!

Perl Weekly Challenge 265: Completing Word

blogs.perl.org

Published by laurent_r on Thursday 18 April 2024 14:50

These are some answers to the Week 265, 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 April 21, 2024 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.

Task 2: Completing Word

You are given a string, $str containing alphanumeric characters and array of strings (alphabetic characters only), @str.

Write a script to find the shortest completing word. If none found return empty string.

A completing word is a word that contains all the letters in the given string, ignoring space and number. If a letter appeared more than once in the given string then it must appear the same number or more in the word.

Example 1

Input: $str = 'aBc 11c'
       @str = ('accbbb', 'abc', 'abbc')
Output: 'accbbb'

The given string contains following, ignoring case and number:
a 1 times
b 1 times
c 2 times

The only string in the given array that satisfies the condition is 'accbbb'.

Example 2

Input: $str = 'Da2 abc'
       @str = ('abcm', 'baacd', 'abaadc')
Output: 'baacd'

The given string contains following, ignoring case and number:
a 2 times
b 1 times
c 1 times
d 1 times

The are 2 strings in the given array that satisfies the condition:
'baacd' and 'abaadc'.

Shortest of the two is 'baacd'

Example 3

Input: $str = 'JB 007'
       @str = ('jj', 'bb', 'bjb')
Output: 'bjb'

The given string contains following, ignoring case and number:
j 1 times
b 1 times

The only string in the given array that satisfies the condition is 'bjb'.

The task specification does not state it explicitly, but the examples show that we should ignore case when comparing letters.

Completing Word in Raku

In Raku, we'll use a Bag, which is a collection of distinct elements that each have an integer weight assigned to them signifying how many copies of that element are considered "in the bag", to store a histogram of the letter frequencies, both for the input test string and the words to which it should be compared. The good thing about it is that we obtain directly a histogram of the input letter list, and that can use the Subset of or equal to operator,infix%E2%8A%86) to check directly the completing condition.

sub complete-word  ($in-str, @in-words) {
    my $letters = $in-str.comb.map({ .lc}).grep( /<[a..z]>/).Bag;
    my @result;
    for @in-words -> $word {
        push @result, $word if $letters ⊆ $word.comb.map({ .lc }).Bag;
    }
    return min(@result, :by( { $_.chars } )); 
}

my @tests = ('aBc 11c', ('accbbb', 'abc', 'abbc')),
            ('Da2 abc', ('abcm', 'baacd', 'abaadc')),
            ('JB 007', ('jj', 'bb', 'bjb'));
for @tests -> @test {
    printf "%-8s - %-20s => ", @test[0], "@test[1]";
    say complete-word @test[0], @test[1];
}

This program displays the following output:

$ raku ./complete-wortd.raku
aBc 11c  - accbbb abc abbc      => accbbb
Da2 abc  - abcm baacd abaadc    => baacd
JB 007   - jj bb bjb            => bjb

Completing Word in Perl

This is a port to Perl of the above Raku program. We use a hash instead of a Bag to store the histogram of the input letters. The use of the subset operator is replaced by a simple loop to find out whether any letter of the input test string is missing (or in smaller number) in the input words.

use strict;
use warnings;
use feature 'say';

sub complete_word {
    my ($in_str, @in_words) = @_;
    my %letters;
    $letters{$_}++ for grep { $_ =~ /[a-z]/ } map { lc } split //, $in_str;
    my @result;
    WORD: for my $word (@in_words) {
        my %word_let;
        $word_let{$_}++ for map { lc } split //, $word;
        for my $k (keys %letters) {
            next WORD unless exists $word_let{$k};
            next WORD if $letters{$k} > $word_let{$k};
        }   
        push @result, $word;
    }
    return (sort {length $a <=> length $b} @result)[0];
}

my @tests = ( ['aBc 11c', ['accbbb', 'abc', 'abbc']],
              ['Da2 abc', ['abcm', 'baacd', 'abaadc']],
              ['JB 007', ['jj', 'bb', 'bjb']]  );
for my $test (@tests) {
    printf "%-8s - %-10s => ", $test->[0], "$test->[1][0] ...";
    say complete_word $test->[0], @{$test->[1]};
}

This program displays the following output:

$ perl ./complete-wortd.pl
aBc 11c  - accbbb ... => accbbb
Da2 abc  - abcm ...   => baacd
JB 007   - jj ...     => bjb

Wrapping up

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 April 28, 2024. And, please, also spread the word about the Perl Weekly Challenge if you can.

Perl Weekly Challenge 265: 33% Appearance

blogs.perl.org

Published by laurent_r on Thursday 18 April 2024 14:45

These are some answers to the Week 265, 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 April 21, 2024 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.

Task 1: 33% Appearance

You are given an array of integers, @ints.

Write a script to find an integer in the given array that appeared 33% or more. If more than one found, return the smallest. If none found then return undef.

Example 1

Input: @ints = (1,2,3,3,3,3,4,2)
Output: 3

1 appeared 1 times.
2 appeared 2 times.
3 appeared 4 times.

3 appeared 50% (>33%) in the given array.

Example 2

Input: @ints = (1,1)
Output: 1

1 appeared 2 times.

1 appeared 100% (>33%) in the given array.

Example 3

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

1 appeared 1 times.
2 appeared 1 times.
3 appeared 1 times.

Since all three appeared 33.3% (>33%) in the given array.
We pick the smallest of all.

33% Appearance in Raku

We coerce the input array into a Bag, which is a collection of distinct elements that each have an integer weight assigned to them, signifying how many copies of that element are considered "in the bag". The good thing about it is that we obtain directly a histogram of the values in the input array. Note that we return Nil rather than undef when no solution because this is more in line with what Raku does in such cases.

sub thirty-three-pct (@in) {
    my $count = @in.elems;
    return Nil if $count == 0;
    my $limit = $count * .33;
    my $histo = @in.Bag;
    my @eligibles = grep { $histo{$_} > $limit }, $histo.keys;
    return @eligibles ?? @eligibles.min !! Nil;
}

my @tests = <1 2 3 3 3 3 4 2>, <1 2>, <1 2 3>, 
            <1 2 1 2 1 2 1 2>, <1 2 3 4 1 2 3 4>;
for @tests -> @test {
    printf "%-18s => ", "@test[]";
    say thirty-three-pct @test;
}

This program displays the following output:

$ raku ./33-pct.raku
1 2 3 3 3 3 4 2    => 3
1 2                => 1
1 2 3              => 1
1 2 1 2 1 2 1 2    => 1
1 2 3 4 1 2 3 4    => Nil

33% Appearance in Perl

This is a port to Perl of the above Raku program. We use a hash instead of a Bag to store the histogram of the input values.

use strict;
use warnings;
use feature 'say';

sub thirty_three_pct {
    my $count = scalar @_;
    return "Undef" if $count == 0;
    my $limit = $count * .33;
    my %histo;
    $histo{$_}++ for @_;
    my @eligibles = sort {$a <=> $b} 
                    grep { $histo{$_} > $limit } keys %histo;
    return @eligibles ? $eligibles[0] : "Undef";
}

my @tests = ([<1 2 3 3 3 3 4 2>], [<1 2>], [<1 2 3>],
             [<1 2 1 2 1 2 1 2>], [<1 2 3 4 1 2 3 4>]);
for my $test (@tests) {
    printf "%-18s => ", "@$test";
    say thirty_three_pct @$test;
}

This program displays the following output:

$ perl ./33-pct.pl
1 2 3 3 3 3 4 2    => 3
1 2                => 1
1 2 3              => 1
1 2 1 2 1 2 1 2    => 1
1 2 3 4 1 2 3 4    => Undef

Wrapping up

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 April 28, 2024. And, please, also spread the word about the Perl Weekly Challenge if you can.

Why I Like Perl's OO

r/perl

Published by /u/pmz on Thursday 18 April 2024 10:13

Perl Comparison string

Perl questions on StackOverflow

Published by SQL Novice on Thursday 18 April 2024 06:58

I am using the below script to compare the output I receive from SNMPGet. The output is in string format and shown below.

SnmpGet v1.01 - Copyright (C) 2009 SnmpSoft Company
[ More useful network tools on http://www.snmpsoft.com ]

OID=.1.3.6.1.4.1.9002.1.3.65.205.166.82.0
Type=Gauge32
Value=3

I need to compare the value in the 6th line of the output (Value=3)

use strict;
use warnings;
my $cmd="D:\\Perl32\\bin\\SnmpGet.exe -r:X.X.X.X -v:3 -sn:Solar -ap:SHA -aw:50 -pp:AES128 -pw:W1nD% -o:1.3.6.1.4.1.9002.1.3.65.205.166.82.0 -t:20";
my $snmpvalue0;
my $msg0;
open(Row2Stat,"$cmd |") || die ("Could not read the pipe\n");
$snmpvalue0 = <Row2Stat>;
close(Row2Stat);
if( $snmpvalue0 eq "Value=3")
{
    $msg0="active";
    $snmpvalue0 ="3";
}
elsif( $snmpvalue0 eq "Value=4" )
{
    $msg0="destroy";
    $snmpvalue0 ="4";
}
print "\nStatistic.Name:$snmpvalue0";
print "\nMessage.Name:$msg0";

I believe I have to use chomp and I am running into an issue with the syntax.Is there a way, I can use it to compare with the 6th line which I have in the output (Value=3)

perldelta updates

Perl commits on GitHub

Published by tonycoz on Thursday 18 April 2024 00:18

perldelta updates

perldiag: update "You need to quote X" %SIG diagnostic

Perl commits on GitHub

Published by mauke on Wednesday 17 April 2024 17:56

perldiag: update "You need to quote X" %SIG diagnostic

The old description was clearly written for perl 4 programmers.

- change "Perl 5" to just "Perl"
- recommend foo() to call subroutines (instead of &foo)
- mention the option of putting a subroutine reference in %SIG

Net::SSH::Expect - jump server then to remote device?

r/perl

Published by /u/jtzako on Wednesday 17 April 2024 17:13

Im working on a script to test using a jump server to reach remote devices.

I'm able to connect to the jump server using Net::SSH::Expect, however, I'm not sure how to then ssh to a remote device (network element).

Is there a way to create that ssh to the remote device inside the jump server's connection?

submitted by /u/jtzako
[link] [comments]

Phishing Attempt on PAUSE Users

blogs.perl.org

Published by Mark Lawrence on Wednesday 17 April 2024 14:06

I just received an E-Mail purporting to be from the PAUSE Team, claiming a compromise of a server. It was written with some thought, referencing the account name of someone well known and trusted in our community. On closer inspection however, it was merely an attempt to phish PAUSE usernames and passwords via a supposed alternative login server.

I'm sure many of us are old enough and experienced enough to detect and ignore this type of attack. But in case you aren't (welcome!) or if you are feeling a bit out of practice, then please remember to only log in via the official PAUSE entry point.

perlfunc: fix split example with limit higher than number of splits

When calling split with a LIMIT higher than the number of possible
output fields, no extra fields will be produced. The previous example
trying to demonstrate this had an error because it used an empty match,
which meant a final empty string could be produced.

allow perl to build with the re extension is static

Perl commits on GitHub

Published by tonycoz on Tuesday 16 April 2024 23:42

allow perl to build with the re extension is static

Previously configuring with -Uusedl built successfully, but didn't
with -Dstatic_ext=re, now both build successfully.

Fixes #21550

Have this code

use 5.034;
use warnings;
#use utf8;
binmode(STDOUT, ':encoding(utf-8)');

package User {
        use Method::Signatures::Simple;
        use Moose;
        has 'name' => (is => 'rw', isa => 'Str', default => sub { return 'foo' });
        method xname { return "čč" . $self->name . "ňň"; }
}

my $u = User->new;
say $u->xname;

It nearly works as expected (not fully correct, because the source code containing utf8.)

After uncommentig the use utf8; the perl -c throws errors:

Couldn't find declarator 'method' at /u/ae/envs/plenv/versions/5.38.2/lib/perl5/site_perl/5.38.2/amd64-freebsd/Devel/Declare/Context/Simple.pm line 47.
    Devel::Declare::Context::Simple::skip_declarator(Method::Signatures::Simple=HASH(0x8292a3fa8)) called at /u/ae/envs/plenv/versions/5.38.2/lib/perl5/site_perl/5.38.2/amd64-freebsd/Devel/Declare/MethodInstaller/Simple.pm line 62
    Devel::Declare::MethodInstaller::Simple::parser(Method::Signatures::Simple=HASH(0x8292a3fa8), "method", 1, 1) called at /u/ae/envs/plenv/versions/5.38.2/lib/perl5/site_perl/5.38.2/amd64-freebsd/Devel/Declare/MethodInstaller/Simple.pm line 25
    Devel::Declare::MethodInstaller::Simple::__ANON__("method", 1) called at /u/ae/envs/plenv/versions/5.38.2/lib/perl5/site_perl/5.38.2/amd64-freebsd/Devel/Declare.pm line 277
    Devel::Declare::linestr_callback("const", "method", 1) called at t line 10

Two questions:

  • why the simple use utf8 pragma interfere with the use Method::Signatures::Simple, and
  • how to use the Method::Signatures::Simple together with the use utf8?

EDIT:

@VonC suggested the Function::Parameters. It looks nice, but it not allows to use the method keyword in the Moose builder sub. E.g.

This not works for me,

    has 'foo' => (is => 'rw', isa => 'Str', default => sub { return 'foo' });
    has 'foobar' => (is => 'rw', isa => 'Str', builder => '_buildfoobar');
    method _buildfoobar {return $self->foo . 'bar' } #note the method

and must use the standard sub and $self shift

    has 'foo' => (is => 'rw', isa => 'Str', default => sub { return 'foo' });
    has 'foobar' => (is => 'rw', isa => 'Str', builder => '_buildfoobar');
    sub _buildfoobar {my $self=shift; return $self->foo . 'bar' }

Anyway, I will accept the solution, if no better comes, because it at least allows the utf8 :).

yyl_dollar: we don't need to diagnose tick-in-id here

Perl commits on GitHub

Published by tonycoz on Tuesday 16 April 2024 22:28

yyl_dollar: we don't need to diagnose tick-in-id here

when scanning for an id for a heuristic.

Fixes #22145

How to manipulate files on different servers

r/perl

Published by /u/QueenScorp on Tuesday 16 April 2024 20:08

First things first, I am a data engineer but have little experience in Perl. I've been able to make some easy updates to scripts in the past but this one is a bit tougher.

I have been asked to update a Perl cgi web app that someone wrote ages ago that is used to view and manipulate text files. Currently it is hosted on server (X) and manipulates the files on that same server. However, we have to have backups/mirrors of the data on a dev server and another prod sever (Y). I.e., if I push the button to move the file to a different folder, it should do that on all three servers instead of just X. I added code to do this, referencing the additional servers with their UNC names, but I just get an error "No such file or directory" (which is not true). Googling has suggested that there may be an issue with permissions, but I can bring up the Y and DEV servers from a windows file explorer using the same path so I don't think that is necessarily the issue.

Example: Here we are trying to copy the file with a letter appended a given number of times. It works fine on the X server, its when trying to make it also work on the Y and DEV servers I get an error.

our $DIR_X = "\\\\serverX\\folder\\subfolder" ; our $DIR_Y = "\\\\serverY\\folder\\subfolder"; our $DIR_DEV = "\\\\serverDEV\\folder\\subfolder"; . . . }elsif ($query->param('action') eq 'split' && $query->param('fileNum') ne "") { my $fileNum $query->param('fileNum'); my $fileX=$DIR_X . "\\" . $fileNum . ".txt"; my $fileY= $DIR_Y . "\\" . $fileNum . ".txt"; my $fileDEV = $DIR_DEV . "\\" . $fileNum . ".txt"; my $splitNbr = $query->param('splitNbr'); my u/letters1("a".. "z"); for (my $i = 0; $i < $splitNbr; $i++) { my $FileNew_X = $DIR_X . "\\" $fileNum. $letters[$i]=.txt"; my $FileNew_Y = $DIR_Y . "\\" $fileNum. $letters[$i]=.txt"; my $FileNew_DEV = $DIR_DEV . "\\" $fileNum. $letters[$i]=.txt"; copy($fileX, $FileNew_X) or die "WARNING: copy failed: $!\n"; ---->>>>>ERROR AT NEXT LINE copy($fileY, $FileNew_Y) or die "WARNING: copy failed: $!\n"; copy($fileDEV, $FileNew_DEV) or die "WARNING: copy failed: $!\n"; } 

Any thoughts?

submitted by /u/QueenScorp
[link] [comments]

The Perl and Raku Conference: Call for Speakers Renewed

Perl Foundation News

Published by Todd Rinaldo on Tuesday 16 April 2024 17:17


The Perl and Raku Conference is fast approaching! We will be in Las Vegas from June 24 to 28 (the main conference is from June 25 to 27).

We want more speakers, so we are reopening the full call for talks/papers/posters. The new deadline is April 20, midnight Las Vegas time (April 21 00:00 UTC). Now that the national eclipse is not a distraction, please consider submitting a talk (50 minute, or 20 minute) or a scientific paper or poster before the new deadline! Speakers will be informed of talk acceptance by April 30.

Talks of 20 minutes or 50 minutes, papers, and posters earn the presenter free admission. Giving a Lightning Talk does not reduce the admission fee but earns our appreciation and delight!

Whether speaker or attendee, we look forward to seeing you in Las Vegas!

Getting Started with perlimports · olafalders.com

r/perl

Published by /u/oalders on Tuesday 16 April 2024 13:59

Installing Tk on Strawberry Perl leads to compiler errors

Perl questions on StackOverflow

Published by Orville Weyrich on Tuesday 16 April 2024 12:54

I am running Strawberry Perl 5, version 38, subversion 0 (v5.38.0) built for MSWin32-x64-multi-thread I downloaded the latest version from CPAN (Tk-804.036) and tried perl makefile.pl but got a number of compiler errors. Following the thread “Tk build fails (Perl 5.36 sp536 20230420)#98" from @HaraldJoerg I made the following changes in the code:

  1. Changed all occurrences of ControlMask to ControlMask_BUGBUG in all .c and .h files in the project, i.e. pTk\mTk\xlib\X11\X.h, pTk\tkBind.c, pTk\tkWinKey.c, pTk\tkWinPointer.c, pTk\tkWinX.c, pTk\mTk\generic\tkBind.c

  2. Changed all occurrences of case SVt_IV: to

    #ifdef HAS_REAL_SVT_RV case SVt_RV: #endif

in all files containing the string SVt_RV, i.e config/svtrv.c, Event\pTkCallback.c

  1. Changed "op_pmdynflags" to "op_pmflags" and deleted the line containing "op_pmpermflags" in file config/pmop.c I was then able to make realclean and then do perl makefile.pl to get a clean compile except for a minor warning from the file config/Hstrdup.c about config/Hstrdup.c: implicit declaration of function 'exit'.

However make test still throws many concerning warnings about casting pointers to the wrong size integers, etc. I did make -i test and make -i install and then tried to run the following program (from the book by Lidie and Walsh):

use Tk;
my $mw = MainWindow->new;
$mw->title("Hello World");
$mw->Button( -text => "Done", -command => sub { exit} ) -> pack;
MainLoop;

This program silently does nothing (returns me to the command prompt without opening a window).

I am new to the arena of editing open-source software like Tk, and do not know how to approach officially submitting what I did to cure the compile errors (not sure why the main branch of Tk is broken in my environment – it must have worked somewhere!). But it still appears broken in some way, even after my changes. I think that the warnings about casting pointers during the test part does not necessarily reflect badly on the code being tested, but only on the test code itself, but I could be wrong. Does anyone know of a working version of Strawberry Perl that plays well with a working version of Tk?

Inviting all programmers to Perl, like Ruby does in "Ruby From Other Languages"

r/perl

Published by /u/Lenticularis39 on Monday 15 April 2024 20:56

I stumbled upon this really nice page from Ruby, describing the language from the perspective of other common programming languages:

https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/

The page is written in a friendly tone, inviting programmers familiar with other programming languages to Ruby. No programming language is being viewed as inferior, quite the contrary: all mentioned languages are praised and even defended from haters, for example:

  • "Perl is awesome. Perl’s docs are awesome. The Perl community is … awesome. For those Perlers who long for elegant OO features built-in from the beginning, Ruby may be for you."
  • "Happily, it turns out that Ruby and C have a healthy symbiotic relationship. And, of course, Ruby itself is written in C."
  • "Java is mature. It’s tested. And it’s fast (contrary to what the anti-Java crowd may still claim)."
  • "Python is another very nice general purpose programming language."

I believe Perl could greatly benefit from having a similar page. With its friendly philosophy and TMTOWTDI, it seems natural to invite programmers from other languages, with an approach of "Don't be afraid to keep programming the way you are used to, if it works in Perl, there are no limits enforced".

Since Perl is now not a common choice for new code or for learning, it makes a lot of sense to bring over people from other languages. Especially in an age where strict conventions seem to be praised, I can see Perl becoming a source of some fresh air.

Edit: I started working on a draft, available in a GitHub repo: https://github.com/lenticularis39/Perl-from-Other-Languages

submitted by /u/Lenticularis39
[link] [comments]

I can still count browser tabs

rjbs forgot what he was saying

Published by Ricardo Signes on Monday 15 April 2024 20:24

A couple years ago, I posted about making a Prometheus exporter for my Chrome tab count. I had fun doing it, but unfortunately it made it onto Hacker News, which as always got a fair bit of missing-the-point. So it goes.

Yesterday, for a mixture of principled reasons and procrastinatory ones, I switched from Chrome to Firefox. Mostly this was easy. I upgraded Firefox, installed some extensions, ported over my open tabs, and that was about it. But I still wanted my tab graph, which surprisingly I have kept using. Firefox is AppleScriptable, but its tiny set of classes doesn’t include anything useful for tab counting. I resorted to parsing the session state file.

This is a trick others have done, but now I have done it too.

use v5.36.0;

use Compress::LZ4;
use JSON::MaybeXS;
use Path::Tiny;

# I should not really hardcode the profile path.  But I don't want to look at
# them all, because it seems sometimes ancient ones linger.  I'll sort it out
# if this ever breaks. -- rjbs, 2024-04-14
my $profiles_root = path('/Users/rjbs/Library/Application Support/Firefox/Profiles');
my $backups_dir   = $profiles_root->child('xyzzy.default/sessionstore-backups');
my $backup_file   = $backups_dir->child('recovery.jsonlz4');

# This is some nonsense container data.  I learned this trick from this blog
# post's code: https://alexandre.deverteuil.net/post/firefox-tabs-analysis/
my $bytes = $backup_file->slurp;
substr $bytes, 0, 8, '';

my $json  = decompress($bytes);
my $data  = decode_json($json);

my $tab_count = 0;
my $window_count = 0;

for my $window ($data->{windows}->@*) {
  $window_count++;
  for my $tab ($window->{tabs}->@*) {
    # I don't use this, but just in case, now I have it.  Each tab's
    # "entries" is history entries for the tab, and the last one is the
    # currently active tab data.
    my $live = $tab->{entries}[-1]; # $live->{url} # <-- real url
    $tab_count++;
  }
}

say "firefox_open_windows $window_count";
say "firefox_open_tabs $tab_count";

This program just spits out two lines of Prometheus-formatted data. Right now, it’s this:

firefox_open_windows 10
firefox_open_tabs 47

I could put this in a little web server running on my laptop, but I’ve mostly avoided setting up any always-running daemons on my Mac. I don’t know why, it just feels like one more hassle. So, instead, I weirdly embedded this in my Hammerspoon init:

ffMetrics = ""

function ffMakeMetricsTask ()
  return hs.task.new(
    "/Users/rjbs/code/hub/rjbs-misc/firefox-prometheus-metrics",
    function (exitCode, stdOut, stdErr)
      ffMetrics = stdOut
    end
  )
end

ffMetricsTimer = hs.timer.doEvery(60, function ()
  if not (ffMetricsTask and ffMetricsTask:isRunning()) then
    ffMetricsTask = ffMakeMetricsTask():start()
  end
end)

Then, in my existing metrics HTTP server run in Hammerspoon, I concatenate ffMetrics into the result.

I am pleased with this solution. It is stupid and works, which I often find a very satisfying combination.

Perl Weekly #664 - German Perl Workshop

dev.to #perl

Published by Gabor Szabo on Monday 15 April 2024 06:52

Originally published at Perl Weekly 664

Hi there,

Today is the Day 1 of the German Perl Workshop 2024. It is going to be very busy week for those attending the annual event. As per the schedule, Curtis Poe is giving talk on AI—This Talk is Always Out of Date. I am pretty sure, it is going to be very popular among the attendees. Most of the talks are going to be in German as expected. English speaking attendees shouldn't worry as there would be some talks in English too. The team behind the GPW is so friendly and welcoming that you would never get bored throughout the day. It feels great to see how they have managed to organise the event every year. There was a time when London Perl Workshop used to be so popular that attracted attendees from as far as Japan just for one day event. Lee Johnson has been pushing hard to make it happen this year. Please show your interest in good numbers if you are LPW fans. Finding Sponsor is the biggest hurdle, if I am not mistaken. I just hope we don't miss the opportunity this year.

Recently I got the shocking news about my friend, Dave Hodgkinson. There was a Facebook post sharing the news that Dave passed away last December. I have had the honour to meet him at every LPW event. He would never miss the opportunity to catch up his friends. He was also regular to the London Perl Mongers meetup. In the last few years when the event didn't happen, he was actively engaging with friends on Facebook. I used to chat with him on Facebook messenger regularly. I still have his message wishing me good luck when I joined Oleeo. This news really shocked me. Last December was so depressing time for me, as I lost my Mom on Boxing day. This is a small tribute to my buddy, Dave. May his soul rest in peace.

Please take extra care of your health and your loved ones.

--
Your editor: Mohammad Sajid Anwar.

Announcements

2024 TPRC Submission Date Extended thru April 20th

The deadline for talk and paper submissions to the 2024 TPRC has been officially extended through April 20th for both the regular Perl and Raku tracks; and also the Science Track.

Articles

This week in PSC (144) | 2024-04-11

Perl Steering Council shared the details of last meetup. Good to see, we are making good progress.

Grants

PEVANS Core Perl 5: Grant Report for March 2024

Paul shared the work done as part of Grant for March 2024. Thank you for your contributions.

Maintaining Perl 5 Core (Dave Mitchell): March 2024

Dave completed tasks to help get blead into shape for the 5.40 release, such as analysing and reducing smoke failures, and fixing bugs.

Maintaining Perl (Tony Cook) January 2024

A thorough detailed breakdown of work carried out by Dave. The list is impressive, thanks for sharing.

The Weekly Challenge

The Weekly Challenge by Mohammad Sajid Anwar will help you step out of your comfort-zone. We pick one champion at the end of the month from among all of the contributors during the month.

The Weekly Challenge - 265

Welcome to a new week with a couple of fun tasks: "33% Appearance" and "Completing Word". If you are new to the weekly challenge, why not join us and have fun every week? For more information, please read the FAQ.

RECAP - The Weekly Challenge - 264

Enjoy a quick recap of last week's contributions by Team PWC dealing with the "Greatest English Letter" and "Target Array" tasks in Perl and Raku. You will find plenty of solutions to keep you busy.

TWC264

Use of CPAN modules can help get you sleek solutions. Well done and thanks for sharing.

Greatest Target

Detailed analysis with complete documentation enough to keep you engaged. Keep it up great work.

Everything Under The Sun Is In Tune

Simple and straight forward logic to deal with the task. You will fall in love with Perl.

Perl Weekly Challenge: Week 264

Classic use of Raku power gives us cool one-liner full of magic. You must checkout.

The Greatest Target

Smoke Test? If you fancy then this is for you. Highly recommended.

Perl Weekly Challenge 264: Greatest English Letter

How much magic do you expect in one solution? Well checkout this week Raku solution and you will be surprised. Thanks for sharing.

Perl Weekly Challenge 264: Target Array

Splice of Perl and Raku are so identical that we have near identical solution. Well done.

array indexes mess

You will find the Raku one-liner very engaging as always. Keep it up great work.

Perl Weekly Challenge 264

Master of Perl one-liner is sharing the trick once again. Well done and thanks for sharing.

The Greatest, the Greatest

Classic demo of Perl power, very impressive. Highly recommend.

I’m The Greatest Target!

We all know the maz() but how many of you know about maxstr()? Keep it up great work.

Greatest letter and mashed arrays

Breaking task into smaller steps make the job so easy. Live demo is the highlight for me as always.

The Weekly Challenge - 264

Thanks for sharing the special use of subsdtr(). You don't see this very often. Keep sharing.

The Weekly Challenge #264

Clever use of Perl regex. I am sure you will take a closer look once again.

Greatest English Array

Rust is the talk of thw town. Thanks for sharing the knowledge with us.

The greatest array

As per the tradition, Python solution is discussed in the blog post. You would agree with me, it looks cute.

Rakudo

2024.14/15 1K+ / 75%+

Weekly collections

NICEPERL's lists

Great CPAN modules released last week;
StackOverflow Perl report.

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.

The greatest array

dev.to #perl

Published by Simon Green on Sunday 14 April 2024 12:54

Weekly Challenge 264

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.

Challenge, My solutions

Task 1: Greatest English Letter

Task

You are given a string, $str, made up of only alphabetic characters [a..zA..Z].

Write a script to return the greatest English letter in the given string.

A letter is greatest if it occurs as lower and upper case. Also letter b is greater than a if b appears after a in the English alphabet.

My solution

For this challenge, I work backwards from z to a and return the first letter that appears in both cases. If str was going to be very long, it would be faster to convert this to a set (hash in Perl) for faster lookup. However this is definitely not needed for a small string.

def greatest_letter(s: str) -> str | None:
    for letter in string.ascii_uppercase[::-1]:
        if letter in s and letter.lower() in s:
            return letter

    return None

Examples

 ./ch-1.py PeRlwEeKLy
L

$ ./ch-1.py ChaLlenge
L

$ ./ch-1.py The
''

Task 2: Target Array

Task

You are given two arrays of integers, @source and @indices. The @indices can only contains integers 0 <= i < size of @source.

Write a script to create target array by insert at index $indices[i] the value $source[i].

My solution

One thing the challenge does not specify is what happens if the value of indices is outside the current length of the of the solution. Python's insert and Perl's splice will append the value to the end of the array (without padding), so I'm following that for this task. It would be trivial to raise an exception if that was the desired behavior.

With that in mind, the task is pretty straight forward. I create an empty list (array in Perl) called solution. I then iterate through the two lists, adding the value in the source list at the position in the indices list.

def target_array(source: list, indices: list) -> list:
    solution = []
    for i in range(len(source)):
        solution.insert(indices[i], source[i])

    return solution

Examples

$ ./ch-2.py "(0, 1, 2, 3, 4)" "(0, 1, 2, 2, 1)"
(0, 4, 1, 3, 2)

$ ./ch-2.py "(1, 2, 3, 4, 0)" "(0, 1, 2, 3, 0)"
(0, 1, 2, 3, 4)

$ ./ch-2.py "(1)" "(0)"
(1)

(cdxci) 4 great CPAN modules released last week

Niceperl

Published by Unknown on Sunday 14 April 2024 10:03

Updates for great CPAN modules released last week. A module is considered great if its favorites count is greater or equal than 12.

  1. App::Netdisco - An open source web-based network management tool.
    • Version: 2.075003 on 2024-04-12, with 16 votes
    • Previous CPAN version: 2.074001 was 24 days before
    • Author: OLIVER
  2. CPAN::Audit - Audit CPAN distributions for known vulnerabilities
    • Version: 20240410.001 on 2024-04-10, with 13 votes
    • Previous CPAN version: 20240401.002 was 9 days before
    • Author: BDFOY
  3. SPVM - SPVM Language
    • Version: 0.989101 on 2024-04-13, with 31 votes
    • Previous CPAN version: 0.989098 was 9 days before
    • Author: KIMOTO
  4. Sys::Virt - libvirt Perl API
    • Version: v10.2.0 on 2024-04-08, with 17 votes
    • Previous CPAN version: v10.1.0 was 1 month, 7 days before
    • Author: DANBERR

(dcviii) stackoverflow perl report

Niceperl

Published by Unknown on Sunday 14 April 2024 09:56

List of new CPAN distributions – Mar 2024

Perlancar

Published by perlancar on Sunday 14 April 2024 00:11

dist author abstract date
AI-Chat BOD Interact with AI Chat APIs 2024-03-02T22:12:10
AI-Image BOD Generate images using OpenAI's DALL-E 2024-03-06T23:01:10
Acme-CPANModules-LoadingModules PERLANCAR List of modules to load other Perl modules 2024-03-01T00:06:07
Acme-CPANModules-LoremIpsum PERLANCAR List of modules related to "Lorem Ipsum", or lipsum, placeholder Latin text 2024-03-02T00:05:10
Acme-CPANModules-OpeningFileInApp PERLANCAR List of modules to open a file with appropriate application 2024-03-04T00:05:56
Acme-CPANModules-RandomText PERLANCAR List of modules for generating random (placeholder) text 2024-03-05T00:05:27
Acme-TaintTest SIDNEY module for checking taint peculiarities on some CPAN testers 2024-03-25T09:22:24
Alien-Pipx CHRISARG Provides the pipx Python Package Manager 2024-03-09T13:19:11
Alien-Qhull DJERIUS Build and Install the Qhull library 2024-03-06T18:15:57
Alien-SeqAlignment-MMseqs2 CHRISARG find, build and install the mmseqs2 tools 2024-03-24T03:33:13
Alien-SeqAlignment-bowtie2 CHRISARG find, build and install the bowtie2 tools 2024-03-19T12:31:34
Alien-SeqAlignment-cutadapt CHRISARG Provide the cutadapt utility for eliminating polyA tails through pipx 2024-03-09T04:49:02
Alien-SeqAlignment-hmmer3 CHRISARG find, build and install the hmmer3 tools 2024-03-22T03:29:12
Alien-SeqAlignment-last CHRISARG find, build and install the last tools 2024-03-16T21:16:36
Alien-SeqAlignment-minimap2 CHRISARG A Perl wrapper for the minimap2 binary executables 2024-03-23T00:58:56
Alien-pipx CHRISARG Provides the pipx Python Package Manager 2024-03-08T20:39:35
Amazon-Sites DAVECROSS A class to represent Amazon sites 2024-03-20T16:18:39
App-BPOMUtils-RPO-Ingredients PERLANCAR Group ingredients suitable for food label 2024-03-10T00:05:30
App-CSVUtils-csv_mix_formulas PERLANCAR Mix several formulas/recipes (lists of ingredients and their weights/volumes) into one, and output the combined formula 2024-03-03T00:06:02
App-ComparerUtils PERLANCAR CLIs related to Comparer 2024-03-06T00:05:48
App-DWG-Sort SKIM Tool to sort DWG files by version. 2024-03-06T10:03:07
App-SortExampleUtils PERLANCAR CLIs related to SortExample 2024-03-07T00:05:25
App-SortKeyUtils PERLANCAR CLIs related to SortKey 2024-03-08T00:05:47
App-SortSpecUtils PERLANCAR CLIs related to SortSpec 2024-03-09T00:05:07
App-SorterUtils PERLANCAR CLIs related to Sorter 2024-03-11T00:05:26
App-SpreadsheetOpenUtils PERLANCAR Utilities related to Spreadsheet::Open 2024-03-12T00:05:23
App-cat-v UTASHIRO cat-v command implementation 2024-03-31T10:58:40
App-chartimes TULAMILI 2024-03-15T01:18:20
App-colcount TULAMILI 各行について、カラムの数を数えたり、条件を満たすカラムの数を数えたりする。 2024-03-15T10:32:37
App-ctransition TULAMILI 入力の全ての文字に対して、次の文字は何であるかの回数の集計を、行列状に表示する。 2024-03-15T12:58:49
App-samelines TULAMILI 2024-03-14T07:49:49
Bencher-Scenario-ListFlattenModules PERLANCAR Benchmark various List::Flatten implementaitons 2024-03-13T00:05:28
Bencher-Scenarios-Text-Table-Sprintf PERLANCAR Scenarios for benchmarking Text::Table::Sprintf 2024-03-14T00:05:21
Bio-SeqAlignment CHRISARG Aligning (and pseudo aligning) biological sequences 2024-03-24T01:05:16
Business-Tax-US-Form_1040-Worksheets JKEENAN IRS Form 1040 worksheets calculations 2024-03-20T19:16:50
CXC-Data-Visitor DJERIUS Invoke a callback on every element at every level of a data structure. 2024-03-23T17:04:24
Carp-Patch-ExcludePackage PERLANCAR Exclude some packages from stack trace 2024-03-15T00:06:01
Comparer-from_sortkey PERLANCAR Compare keys generated by a SortKey:: module 2024-03-16T00:05:16
Compression-Util TRIZEN Implementation of various techniques used in data compression. 2024-03-21T01:02:57
Data-Dump-HTML-Collapsible PERLANCAR Dump Perl data structures as HTML document with collapsible sections 2024-03-08T08:22:33
Data-Dump-HTML-PopUp PERLANCAR Dump Perl data structures as HTML document with nested pop ups 2024-03-18T13:24:01
Data-Dump-IfSmall PERLANCAR Like Data::Dump but reference with dump larger than a certain size will be dumped as something like 'LARGE:ARRAY(0x5636145ea5e8)' 2024-03-18T00:06:06
Data-Dump-SkipObjects PERLANCAR Like Data::Dump but objects of some patterns are dumped tersely 2024-03-19T00:05:05
Data-Navigation-Item SKIM Data object for navigation item. 2024-03-04T11:53:10
Date-Holidays-Adapter-USA GENE Adapter for USA holidays 2024-03-19T20:38:52
Date-Holidays-USA GENE Provides United States of America holidays 2024-03-19T20:09:45
Devel-Confess-Patch-UseDataDumpIfSmall PERLANCAR Use Data::Dump::IfSmall format refs 2024-03-20T00:05:59
Devel-Confess-Patch-UseDataDumpSkipObjects PERLANCAR Use Data::Dump::SkipObjects to stringify some objects 2024-03-21T00:06:11
Dist-Zilla-Plugin-Sah-SchemaBundle PERLANCAR Plugin to use when building Sah-SchemaBundle-* distribution 2024-03-22T00:05:48
Dist-Zilla-Role-GetDistFileURL PERLANCAR Get URL to a file inside a Perl distribution 2024-03-23T00:05:56
GCC-Builtins BLIAKO access GCC compiler builtin functions via XS 2024-03-19T13:31:21
ImgurAPI DILLANBH Imgur API client 2024-03-20T03:11:21
ImgurAPI-Client DILLANBH 2024-03-20T03:31:39
Intellexer-API HAX Perl API client for the Intellexer, a webservice that, "enables developers to embed Intellexer semantics products using XML or JSON." 2024-03-04T02:34:33
LaTeX-Easy-Templates BLIAKO Easily format content into PDF/PS/DVI with LaTeX templates. 2024-03-15T21:43:58
Markdown-Perl MATHIAS Very configurable Markdown processor written in pure Perl, supporting the CommonMark spec and many extensions 2024-03-31T21:17:51
Module-Features-PluginSystem PERLANCAR Features of modules that generate text tables 2024-03-25T00:05:33
Module-Pluggable-_ModuleFeatures PERLANCAR Features declaration for Module::Pluggable 2024-03-26T00:05:20
Net-MailChimp ARTHAS Perl library with MINIMAL interface to use MailChimp API. 2024-03-14T13:52:35
Net-OpenVPN-Manager ATOY Start OpenVPN Manager and return PSGI handler 2024-03-08T18:07:11
Net-PaccoFacile ARTHAS Perl library with MINIMAL interface to use PaccoFacile API. 2024-03-01T16:16:12
OpenAPI-PerlGenerator CORION create Perl client SDKs from OpenAPI specs 2024-03-24T11:02:37
Plack-App-CPAN-Changes SKIM Plack application for CPAN::Changes object. 2024-03-14T18:23:48
Plack-Middleware-Static-Precompressed ARISTOTLE serve a tree of static pre-compressed files 2024-03-14T11:30:12
Plugin-System-_ModuleFeatures PERLANCAR Features declaration for Plugin::System 2024-03-27T00:05:42
Qhull DJERIUS a really awesome library 2024-03-05T20:37:59
Regexp-IntInequality HAUKEX generate regular expressions to match integers greater than / less than / etc. a value 2024-03-08T17:59:24
Sah-SchemaBundle PERLANCAR Convention for Sah-SchemaBundle-* distribution 2024-03-28T00:05:49
Sah-SchemaBundle-Array PERLANCAR Sah schemas related to array type 2024-03-29T00:05:36
Sah-SchemaBundle-ArrayData PERLANCAR Sah schemas related to ArrayData 2024-03-30T00:05:33
Sah-SchemaBundle-Binary PERLANCAR Sah schemas related to binary data 2024-03-17T00:05:16
Sah-SchemaBundle-Bool PERLANCAR Sah schemas related to bool data type 2024-03-24T00:05:52
Sah-SchemaBundle-BorderStyle PERLANCAR Sah schemas related to BorderStyle 2024-03-31T00:05:05
Tags-HTML-CPAN-Changes SKIM Tags helper for CPAN::Changes object. 2024-03-14T09:55:49
Template-Plugin-Package PETDANCE allow calling of class methods on arbitrary classes that do not accept the class name as their first argument. 2024-03-12T04:32:11
Tk-FileBrowser HANJE Multi column file system explorer 2024-03-29T21:22:08
WWW-Gemini ANTONOV 2024-03-11T02:51:49
lib-root HERNAN find perl root and push lib modules path to @INC 2024-03-30T17:27:02

Stats

Number of new CPAN distributions this period: 78

Number of authors releasing new CPAN distributions this period: 25

Authors by number of new CPAN distributions this period:

No Author Distributions
1 PERLANCAR 33
2 CHRISARG 9
3 SKIM 4
4 TULAMILI 4
5 DJERIUS 3
6 BOD 2
7 ARTHAS 2
8 GENE 2
9 BLIAKO 2
10 DILLANBH 2
11 HERNAN 1
12 UTASHIRO 1
13 DAVECROSS 1
14 TRIZEN 1
15 ARISTOTLE 1
16 HAX 1
17 HANJE 1
18 JKEENAN 1
19 HAUKEX 1
20 MATHIAS 1
21 CORION 1
22 ATOY 1
23 PETDANCE 1
24 ANTONOV 1
25 SIDNEY 1

2024 TPRC Submission Date Extended thru April 20th

blogs.perl.org

Published by Brett Estrade on Thursday 11 April 2024 22:00

The deadline for talk and paper submissions to the 2024 TPRC has been Officially extended through April 20th for both the regular Perl and Raku tracks; and also the Science Track.

Update for the Science Track submissions, we have a small, but solid set of submissions and are expecting a few more. The Science Perl Committee is committed to helping anyone submitting a serious entry to succeed. If you're hesitating at all because you're afraid of getting rejected, please be reassured we want as many people to be part of this inaugural Science Track, as possible.

Please note, acceptable topics DO include white papers discussing implementation details of the Perl or Raku interpreters, experimental language features, implementations, benchmarks, etc.

I personally and strongly encourage you to submit an abstract to the Science Track. And if you don't want to write a paper, I strongly encourage you to submit a regular conference talk.

Brett Estrade (OODLER)

This week in PSC (144) | 2024-04-11

blogs.perl.org

Published by Perl Steering Council on Thursday 11 April 2024 20:59

The three of us met, and:

  • merged the deëxperiment PR
  • agreed we should additionally discuss if the now-stable features (try, extra_paired_delimiters) should be included in the :5.40 feature bundle
  • reported feedback from PPC implementors, which can be summarized as “life happened, will get back to work soon”
  • continued to triage latest reported bugs and look for release blockers (Currently we have 8 potential blockers, though 2 are easy documentation fixes)

Exploring Programming Languages — Perl

Perl on Medium

Published by Blag aka Alvaro Tejada Galindo on Thursday 11 April 2024 17:59

Let’s continue our exploration of programming languages, with another well know language although not always loved, Perl.

Maintaining Perl 5 Core (Dave Mitchell): March 2024

Perl Foundation News

Published by alh on Tuesday 09 April 2024 13:03


Dave writes:

This is my monthly report on work done during March 2024 covered by my TPF perl core maintenance grant.

Less hours than normal last month due to a combination of jury service and the consequences of spending lots of time with my fellow jurors.

I spent my time mainly on general small tasks to help get blead into shape for the 5.40 release, such as analysing and reducing smoke failures, and fixing bugs.

SUMMARY: * 1:39 "Variable is not available" warning on nested evals * 3:44 #21784 BBC: Blead breaks MLEHMANN/Coro-6.57.tar.gz * 4:15 make stack reference counted - XS * 2:22 process p5p mailbox * 1:38 reduce smoke failures * 1:38 review Coverity reports * 7:42 rework XS documentation

TOTAL: * 22:58 (HH::MM)

PEVANS Core Perl 5: Grant Report for March 2024

Perl Foundation News

Published by alh on Tuesday 09 April 2024 07:47


Paul writes:

``` Hours:

2 = builtin::is_inf + is_nan (as yet unfinished) https://github.com/Perl/perl5/pull/22059

1 = Tidying up PADNAMEf_TOMBSTONE https://github.com/Perl/perl5/pull/22063

1 = Revert PR 21915 https://github.com/Perl/perl5/pull/22085

2 = C99 named initialisers in MGVTBL structs https://github.com/Perl/perl5/pull/22086

4 = perl 5.39.9 release https://metacpan.org/release/PEVANS/perl-5.39.9

Total: 10 hours ```

Maintaining Perl (Tony Cook) January 2024

Perl Foundation News

Published by alh on Tuesday 09 April 2024 07:43


Tony writes:

``` [Hours] [Activity] 2024/01/02 Tuesday 0.18 #21759 review and approve 0.17 #21705 review and approve 0.08 #21736 review and approve 0.33 #21757 review and approve 0.22 #21749 review and approve 0.08 #21778 review and approve 1.43 #21745 review in progress

0.67 #21745 more review and approve, comment

3.16

2024/01/03 Wednesday 0.10 #21761 review and approve 0.32 extract RC_STACK pp_backtick from an experiment, push for CI 0.15 #21734 review and approve 0.08 #21739 review and conditionally approve 0.70 #21740 review and comment 0.10 check CI results and make PR 21789 0.05 #21754 review and comment 0.32 #21764 review, research and approve 0.13 #21767 review and approve 0.18 #21769 review, research and comment 0.20 #21770 review, comment and approve 0.15 #21789 follow-up comment 0.10 #21772 review and approve 0.20 #21773 review 0.33 #21773 more review and approve 0.18 #21771 review and approve 0.08 #21776 review and approve 0.10 #21777 review and approve 0.08 #21786 review and approve

0.23 #21790 review and approve

3.78

2024/01/04 Thursday 0.25 github notifications 0.95 list, native data checks, comment on the linked spec 0.30 #21754 review update and approve 0.08 #21792 review and approve 0.08 #21793 review and approve 0.07 #21794 review and approve 1.47 #21791 review, testing, comments, approve 0.18 #21737 re-check and apply to blead

0.42 #16608 debugging

3.80

2024/01/08 Monday 0.18 github notifications 0.08 #21798 review and approve 0.93 #21796 start review, comment

2.70 #21796 follow-up, more review

3.89

2024/01/09 Tuesday

0.50 #21796 issue fixed, re-check force pushed commits, approve

0.50

2024/01/10 Wednesday 0.08 #21808 review and approve 0.47 #21801 review and comment 0.08 #21810 review and approve 0.38 #21805 review discussion and request some info 2.32 #21782 research, comment on CPAN ticket, work on a fix and push for CI 0.10 #21782 check CI results, make PR 21813 1.25 #21751 research, reproduce on modern darwin, test fix on modern darwin and push for CI

0.47 #21724 research, testing

5.15

2024/01/11 Thursday 0.52 #21813 apply to blead, perldelta 1.77 review Dave’s XS post to ML, research and comment 0.08 #21751 review CI results and make PR 21818 0.08 #21801 review updates and approve 0.07 #21803 review discussion and ask for some info 0.15 #21815 review and approve 0.33 #21814 review, research and comment 0.25 #15108 work up a small doc update and push for CI

0.32 #21814 review updates, research and approve

3.57

2024/01/15 Monday 1.38 #21821 investigate why bad link didn’t result in an error, find many similar errors, testing on perldoc.perl.org and metacpan, fixes, testing and push 0.70 #21820 review and approve 2.65 warnings on win32 gcc builds, testing, research (-Wformat is broken), push for CI

0.18 #21832 review and comment

4.91

2024/01/16 Tuesday 0.63 review coverity scan results, discuss one with khw, comment on original pull request for the other 0.80 #21832 review changes, research and approve 0.08 #21837 review and approve 0.75 #21833 review, research and comment 0.25 #21834 review and approve 0.43 #21840 review and approve 0.48 #21824 review code and discussion

0.30 warnings on win32 gcc builds: open pR 21842

3.72

2024/01/17 Wednesday 0.08 #21842 apply to blead 0.33 #21833 review modifications, research, comment and approve 0.43 #21843 review and approve 0.08 #21844 review and approve 1.08 #21091 research based on latest comment and follow-up comment 0.62 #21550 research

0.58 #21550 more research

3.20

2024/01/18 Thursday 0.35 #21833 research and comment 0.97 look over use VERSION -> builtin thread, review #21850 and approve 0.08 #21845 review and approve 0.42 #21846 review, research and approve 0.38 #21847 review, consider other comments, comment and approve 0.15 #21848 review 0.48 #21550 static build detection and testing

0.95 #21550 reading code

3.78

2024/01/22 Monday 0.43 #21833 review updates and approve 0.08 #21853 review and approve 0.13 #21855 review and approve with comment 0.22 #21856 review and approve 0.08 #21857 review and approve 0.13 #21858 review and approve 0.12 #21859 review and approve 0.12 #21862 review and approve

0.08 #21863 review and approve

1.39

2024/01/23 Tuesday 0.90 #21850 review updates and comment 0.13 #21868 review and approve 0.08 #21869 briefly review and approve 0.30 #21871 review, briefly research and comment, brief discussion, research on #21850 in #p5p

0.92 #21872 review

2.33

2024/01/25 Thursday 1.18 #21872 more review, testing, comment 0.35 #21850 review changes and approve 0.72 #21877 try to reproduce and profile (build issues with - pg)

2.15 #21877 testing, review code, comment

4.40

2024/01/29 Monday 0.30 github notifications 0.63 #21872 consider builtin implementation vs RC_STACK, find why it works 0.53 #21874 review and comment 0.15 #21844 review and comment 1.25 #21885 review, research, testing and comment 0.07 #21866 review and approve 0.40 #21887 review, research and comment 0.08 #21891 review and approve

2.23 #21877 profiling, review code, comment

5.64

2024/01/30 Tuesday 0.50 review coverity scan results, work up a fix and push for CI 1.43 #21877 long comment 0.57 #21884 comment 0.13 coverity scan result follow-up: check CI, open PR #21910 1.55 #16607 also look into handling hwm for xsubs properly,

find several broken XS, (including EU::PXS generated code)

4.18

2024/01/31 Wednesday 0.13 #21884 review updates and approve 0.15 #21883 review and approve 0.45 #21873 testing, research and comment 0.32 #21878 research and comment 0.17 #21906 review and apply to blead 0.62 #16607 research, follow-up on related comment on #21872

0.45 #21897 review, research and comment

2.29

Which I calculate is 59.69 hours.

Approximately 88 tickets were reviewed or worked on, and 4 patches were applied. ```

Perl Weekly #663 - No idea

dev.to #perl

Published by Gabor Szabo on Monday 08 April 2024 07:09

Originally published at Perl Weekly 663

Hi there

It seems I have less and less to write about in these editorials. This is of course not very surprising as I there are fewer and fewer articles published about Perl. The only thing that still keeps this afloat is the Weekly Challenge of Mohammad. So maybe you can sponsor it?

Sad news: Just a few days ago I heard that Dave Hodgkinson has passed away last December. LinkedIn, Facebook, and his web site where he posted in November. May he rest in peace and his family find solace. He will be missed.

In a totally unrelated sadness: It has been six months.

I wish you a nicer week!

--
Your editor: Gabor Szabo.

Articles

A FOSS Ecosystem Checklist for the Benefit of Maintainer Sustainability

Collecting talks

Have you ever enjoyed a presentation or a course given by Dave Cross? Well, his beginnings were humble, to say the least, but luckily he did not have time to give up. Anyway, here is an opportunity for Internet archeologists to help Dave.

Perl programming using KDE's Kate editor in Linux tutorial

A video

PDL 2.087 released and a summary of a ~year of PDL

Discussion

Any new developments in webperl?

Breaking up a 7300 line .pm

Perl

This Week in PSC (143)

The Weekly Challenge

The Weekly Challenge by Mohammad Sajid Anwar will help you step out of your comfort-zone. We pick one champion at the end of the month from among all of the contributors during the month.

The Weekly Challenge - 264

Welcome to a new week with a couple of fun tasks "Greatest English Letter" and "Target Array". If you are new to the weekly challenge then why not join us and have fun every week. For more information, please read the FAQ.

RECAP - The Weekly Challenge - 263

Enjoy a quick recap of last week's contributions by Team PWC dealing with the "Target Index" and "Merge Items" tasks in Perl and Raku. You will find plenty of solutions to keep you busy.

TWC263

Don't you love map{}? See yourself how it can make your code look cute.

Target Merge

Method chaining of Raku makes it easy to create one-liner. Raku Rocks !!!

Don't Sort It, Be Happy

Educational task analysis, you really don't want to skip, thanks for sharing.

Arrayed Against Me

Have you used postderef? It is regular in Dave's contribution. Please do checkout.

The Weekly Challenge - 263

Get thorough task analysis and discussion about weekly tasks. Keep it up great work.

Which Witch?

I highly encourage everyone to try PDL if not done already. I would one day soon. Well done.

Perl Weekly Challenge 263: Target Index

This week favourite is grep and sort. You will appreciate the clean code. Thanks for sharing.

Perl Weekly Challenge 263: Merge Items

Just good old for-loop and no magics. Love the simplicity, keep it up.

iterating and filtering arrays

Magical one-liner in Raku is not to be missed. Great work.

Perl Weekly Challenge 263

This week tasks were ideal for the master of Perl one-liners. Highly recommended.

Indexes and Items

I like the story behnd the scene. There are plenty to learn from such story. Thanks for sharing.

Merge the Target Index Items

Lots of Raku magic in action, makes it special. You will fall in love with the language. Well done and keep it up.

Find the target and merge the inventory

Cute and easy to follow solutions in Perl. Anybody can follow it and try it. Thanks for sharing.

The Weekly Challenge - 263

I have no clue why avoiding the use of 'my' in declaring variables. I would love to know the reason behind it.

The Weekly Challenge #263

Clever use of CPAN module. I always encourage the use of CPAN module. Well done.

Targets Merge

My personal favourite this week is Postscript solution. How about you? Keep it up great work.

Finding the target

Couple of interesting thing about Python in this week post. One, use of array as parameter and return list. You don't want to miss it.

Weekly collections

NICEPERL's lists

Great CPAN modules released last week;
MetaCPAN weekly report;

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.

Collecting talks

Perl Hacks

Published by Dave Cross on Sunday 07 April 2024 17:29

I gave my first public talk sometime between the 22nd and 24th September 2000. It was at the first YAPC::Europe which was held in London between those dates. I can’t be any more precise because the schedule is no longer online and memory fades.

I can, however, tell you that the talk was a disaster. I originally wasn’t planning to give a talk at all, but my first book was about to be published and the publishers thought that giving a talk about it to a room full of Perl programmers would be great marketing. I guess that makes sense. But what they didn’t take into account was the fact that I knew nothing about how to give an interesting talk. So I threw together a few bullet points taken from the contents of the book and wrote a simple Perl script to turn those bullet points into HTML slides (it was 2000 – that’s what everyone did). I gave absolutely no thought to what the audience might want to know or how I could tell a story to guide them through. It was a really dull talk. I’m sorry if you were in the audience. Oh, and add the fact that I was speaking after the natural raconteur, Charlie Stross and you can probably see why I’m eternally grateful that the videos we took of the conference never saw the light of day. I left the stage knowing for sure that public speaking was not for me and vowed that I would never give another talk.

But…

We were experimenting with a session of lightning talks at the conference and I had already volunteered to give a talk about my silly module Symbol::Approx::Sub. I didn’t feel that I could back out and, anyway, it was only five minutes. How bad could it be?

As it turns out, with Symbol::Approx::Sub I had stumbled on something that was simultaneously both funny and useful (well, the techniques are useful – obviously the module itself isn’t). And I accidentally managed to tell the story of the module engagingly and entertainingly. People laughed. And they clapped enthusiastically at the end. I immediately changed my mind about never speaking in public again. This was amazing. This was as close as I was ever going to get to playing on stage at the Hammersmith Odeon. This was addictive.

But something had to change. I had to get better at it. I had to work out how to give entertaining and useful talks that were longer than five minutes long. So I studied the subject of public speaking. The Perl community already had two great public speakers in Mark Dominus and Damian Conway and I took every opportunity to watch them speak and work out what they were doing. It helped that they both ran courses on how to be a better public speaker. I also read books on the topic and when TED talks started coming online I watched the most popular ones obsessively to work out what people were doing to give such engaging talks (it turns out the answer really boils down to – taking out most of the content!)

And I practiced. I don’t think there was a conference I went to between 2000 and 2020 where I didn’t give a talk. I’d never turn down an opportunity to speak at a Perl Mongers meeting. And. while I’m certainly not Damian Conway, I like to think I got better at it. I’d get pretty good scores whenever there was a feedback form.

All of which means that I’ve given dozens of talks over the last twenty-plus years. From lightning talks to all-day (actually, a couple of two-day) training sessions. I’ve tried to be organised about keeping copies of the slides from all of the talks I’ve given, but I fear a few decks have slipped through the cracks over the years. And, of course, there are plenty of videos of me giving various talks over that time.

I’ve been thinking for a while that it would be good to gather them all together on one site. And, a couple of weeks ago. I started prodding at the project. Today, it reached the stage where it’s (just barely) useable. It’s at talks.davecross.co.uk. Currently, it’s just a list of talk titles and it only covers the last five years or so (and for a lot of that time, there were no conferences or meetings to speak at). But having something out there will hopefully encourage me to expand it in two dimensions:

  • Adding descriptions of the talks along with embedded slides and video
  • Adding more talks

The second point is going to be fun. There will be some serious data archaeology going on. I think I can dig out details of all the YAPCs and LPWs I’ve spoken at – but can I really find details of every London Perl Mongers technical meeting? And there are some really obscure things in there – I’m pretty sure I spoke at a Belgian Perl Workshop once. And what was that Italian conference held in Ferrara just before the Mediterranean Perl Whirl? There’s a lot of digging around in the obscure corners of the web (and my hard disk!) in my near future.

Wish me luck.

The post Collecting talks first appeared on Perl Hacks.

Finding the target

dev.to #perl

Published by Simon Green on Sunday 07 April 2024 08:32

Weekly Challenge 263

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.

Challenge, My solutions

Task 1: Target Index

Task

You are given an array of integers, @ints and a target element $k.

Write a script to return the list of indices in the sorted array where the element is same as the given target element.

My solution

This is a pretty straight forward task, so doesn't require much explanation. I sort the array (numerically), and then return the index of items that equally k in the list.

def target_index(ints: list, k: int) -> list:
    ints = sorted(ints)
    return [pos for pos, value in enumerate(ints) if value == k]

Examples

$ ./ch-1.py 1 5 3 2 4 2 2
(1, 2)

$ ./ch-1.py 1 2 4 3 5 6
()

$ ./ch-1.py 5 3 2 4 2 1 4
(4)

Task 2: Merge Items

Task

You are given two 2-D array of positive integers, $items1 and $items2 where element is pair of (item_id, item_quantity).

Write a script to return the merged items.

My solution

My solution to this task is broken into two chunks. The first is to calculate the cumulative totals for each item. While the task mentioned items1 and items2 as variables, I've use the more meaningful variables item_id and item_qty.

from collections import defaultdict

def merge_items(*arrays) -> list:
    # Calculate the total of each items
    totals = defaultdict(int)
    for array in arrays:
        for item in array:
            item_id, item_qty = item
            totals[item_id] += item_qty

The second part of the task is turning the dict (hash in Perl) into a list of item_id and item_qty pairs. This can be done in a single line with list comprehension.

    return [[item, totals[item]] for item in sorted(totals)]

Examples

$ ./ch-2.py "[ [1,1], [2,1], [3,2] ]" "[ [2,2], [1,3] ]"
[[1, 4], [2, 3], [3, 2]]

$ ./ch-2.py "[ [1,2], [2,3], [1,3], [3,2] ]" "[ [3,1], [1,3] ]"
[[1, 8], [2, 3], [3, 3]]

$ ./ch-2.py "[ [1,1], [2,2], [3,3] ]" "[ [2,3], [2,4] ]"
[[1, 1], [2, 9], [3, 3]]

(cdxc) 7 great CPAN modules released last week

Niceperl

Published by Unknown on Sunday 07 April 2024 08:39

Updates for great CPAN modules released last week. A module is considered great if its favorites count is greater or equal than 12.

  1. CPAN::Audit - Audit CPAN distributions for known vulnerabilities
    • Version: 20240401.002 on 2024-04-01, with 13 votes
    • Previous CPAN version: 20240329.002 was 2 days before
    • Author: BDFOY
  2. Firefox::Marionette - Automate the Firefox browser with the Marionette protocol
    • Version: 1.55 on 2024-04-06, with 16 votes
    • Previous CPAN version: 0.77 was 4 years, 8 months, 30 days before
    • Author: DDICK
  3. Imager - Perl extension for Generating 24 bit Images
    • Version: 1.024 on 2024-04-06, with 65 votes
    • Previous CPAN version: 1.023 was 2 months, 18 days before
    • Author: TONYC
  4. Compress::Zlib - IO Interface to compressed data files/buffers
    • Version: 2.211 on 2024-04-06, with 16 votes
    • Previous CPAN version: 2.207 was 1 month, 17 days before
    • Author: PMQS
  5. Net::Curl - Perl interface for libcurl
    • Version: 0.56 on 2024-04-01, with 18 votes
    • Previous CPAN version: 0.55 was 6 months, 11 days before
    • Author: SYP
  6. PDL - Perl Data Language
    • Version: 2.087 on 2024-04-05, with 52 votes
    • Previous CPAN version: 2.085 was 2 months, 6 days before
    • Author: ETJ
  7. SPVM - SPVM Language
    • Version: 0.989098 on 2024-04-04, with 31 votes
    • Previous CPAN version: 0.989096 was 8 days before
    • Author: KIMOTO

(dlxxxv) metacpan weekly report - Firefox::Marionette

Niceperl

Published by Unknown on Sunday 07 April 2024 08:37

This is the weekly favourites list of CPAN distributions. Votes count: 55

Week's winner: Firefox::Marionette (+2)

Build date: 2024/04/07 06:36:52 GMT


Clicked for first time:


Increasing its reputation:

How to Enhance Your Perl Web Applications with HTML and CSS

Perl on Medium

Published by Robert McMenemy on Thursday 04 April 2024 05:34

PWC 263.1 Don't Sort It, Be Happy

dev.to #perl

Published by Bob Lied on Wednesday 03 April 2024 22:18

PWC 263, Task 1 Target Index

Here's a little blog I wrote. You might want to read it note for note.

You are given an array of integers, @ints, 
and a target element $k.

Write a script to return the list of indices
in the sorted array where the element is the
same as the given target element.

Example 1

  • Input: @ints = (1, 5, 3, 2, 4, 2), $k = 2
  • Output: (1, 2)
    • Sorted array: (1, 2, 2, 3, 4, 5)
    • Target indices: (1, 2) as $ints[1] = 2 and $ints[2] = 2

Dive right in

Well, the example gives it away, doesn't it? Sort the array and waddle up the list to the first index where $k exists. Then, because the array is sorted, all the other places where $k exists must be adjacent.

Or not

But hold on. In every algorithm we have some trouble, but when you sort you make it double.

All the $k together means we've effectively partitioned the array into three sets: elements that are less than $k, elements equal to $k, and the rest.

We don't have to sort the array at all. We just have to traverse the array and count the elements in the first two partitions.

sub targetIndex($k, @ints)
{
    my ($below, $same) = (0, 0);
    foreach ( @ints )
    {
        if    ( $_ < $k )  { $below++ }
        elsif ( $_ == $k ) { $same++ }
    }
    return [] if $same == 0;
    return [ $below .. ($same + $below - 1) ];
}

If $k doesn't appear at all, we can bail out by returning an empty list. $below and $same tell us the range of numbers we need in the answer.

$below = 1 # 1 element less than $k
$same  = 2 # 2 elements equal to $k
      {         } 
   1  {  2   2  }   3   4   5
  [0] { [1] [2] }  [3] [4] [5]
         ^   ^
         |   +---- $below + $same -1 = 1+2-1 = 2
  $below-+

The .. range operator makes short work of creating the sequence of numbers we want.

Put that range of numbers into an array, and we have our answer. This function is returning array references, not arrays, so the calling function will have to de-reference. In context, it might look like

say "(", join(",", targetIndex($Target, @ARGV)->@*), ")";

Now there is the blog I wrote. I hope you liked the way I code. Don't worry, be hacker.

(cdlxxxix) 4 great CPAN modules released last week

Niceperl

Published by Unknown on Saturday 30 March 2024 22:52

Updates for great CPAN modules released last week. A module is considered great if its favorites count is greater or equal than 12.

  1. CPAN::Audit - Audit CPAN distributions for known vulnerabilities
    • Version: 20240329.002 on 2024-03-29, with 13 votes
    • Previous CPAN version: 20240318.001 was 10 days before
    • Author: BDFOY
  2. SPVM - SPVM Language
    • Version: 0.989096 on 2024-03-27, with 31 votes
    • Previous CPAN version: 0.989092 was 4 days before
    • Author: KIMOTO
  3. URI - Uniform Resource Identifiers (absolute and relative)
    • Version: 5.28 on 2024-03-27, with 113 votes
    • Previous CPAN version: 5.27 was 1 month, 18 days before
    • Author: OALDERS
  4. WWW::Mechanize::Chrome - automate the Chrome browser
    • Version: 0.73 on 2024-03-29, with 22 votes
    • Previous CPAN version: 0.72 was 4 months, 8 days before
    • Author: CORION

Amazon Links and Buttons

Perl Hacks

Published by Dave Cross on Saturday 30 March 2024 12:59

I’ve spent more than a reasonable amount of time thinking about Amazon links over the last three or four years.

It started with the Perl School web site. Obviously, I knew that the book page needed a link to Amazon – so people could buy the books if they wanted to – but that’s complicated by the fact that Amazon has so many different sites and I have no way of knowing which site is local to anyone who visits my web site. I had the same problem when I built a web site for George and the Smart Home. And again when I created a site for Will Sowman’s books. At some point soon, I’ll also want to put book pages on the Clapham Tech Press web site – and that will have exactly the same problem.

That’s the user-visible side of the equation. There are other reasons for wanting to know about all of the existing Amazon sites. One of the best ones is because I want to track royalties from the various sites and apportion them to the right authors.

On the Perl School site, I solved the problem by creating a database table which contains data about the sites that I knew about at the time. Then there’s a DBIC result class and that result set is passed to the book page template, which builds “buy” buttons for each site found in the result set. That works, but it’s not very portable. When it came to the other sites, I found myself writing a “make_buttons” program which used the Perl School database table to generate some HTML which I then copied into the relevant template.

But that never sat well with me. It made me uncomfortable that all of my book sites relied on a database table that existed in one of my repos that, really, has no connection to those other sites. I thought briefly about duplicating the table into the other repos, but that set off the “Don’t Repeat Yourself” alarm in my head, so I backed away from that idea pretty quickly.

It would be great if Amazon had an API for this information. But, unless I’m blind, it seems to be the only API that they don’t provide.

So, currently, what I’ve done is to encapsulate the data in a CPAN module. It’s called Amazon::Sites and I’ve been releasing slowly-improving versions of it over the last week or so – and it’s finally complete enough that I can use it to replace my database table. It might even make the code for my various book sites easier to maintain.

Maybe it will be useful to you too.

Here’s how you use it:

use Amazon::Sites;
 
my $sites = Amazon::Sites->new;
my @sites = $sites->sites;
my %sites = $sites->sites_hash;
my @codes = $sites->codes;
 
my $site  = $sites->site('UK');
say $site->currency; # GBP
say $site->tldr;     # co.uk
# etc
 
my %urls = $sites->asin_urls('XXXXXXX');
say $urls{UK}; # https://amazon.co.uk/dp/XXXXXXX

Once you’ve created a class of the object, you have access to a few useful methods:

  • sites – returns a list of all of the sites the object knows about. Each element in  the list is an Amazon::Site object
  • sites_hash – returns the same information, but as a hash. The key is a two-letter ISO country code and the value is an Amazon::Site object
  • codes – returns a list of all of the country codes that the object knows about
  • site(country_code) – expects a two-letter ISO country code and returns the Amazon::Site object for that country’s Amazon site

The Amazon::Site object has a number of useful attributes:

  • code – the country code
  • country – the country’s name in English
  • currency – the ISO code for the currency used on that site
  • tldn – the top-level domain name that the Amazon site uses (e.g. .com or .co.uk)
  • domain – the full domain that the Amazon site used (e.g. amazon.com or amazon.co.uk)

Amazon::Site also has a “asin_url()” method. You pass it an ASIN (that’s the unique identifier that Amazon uses for every product on its site) and it returns the full URL of that product on that site. There’s a similar “asin_urls()” (note the “s” at the end) on the Amazon::Sites object. That returns a hash of URLs for all of the sites the object knows about. The key is the country code and the value is the URL in that country.

You can also filter the list of Amazon sites that you’re interested in when creating your Amazon::Sites object. The constructor takes optional “include” and “exclude” arguments. Each of them is a reference to an array of ISO country codes. For reasons that are, I hope, obvious, you can only use one of those options at a time.

If you’re an Amazon Associate, you can make money by including your “associate code” in Amazon URLs that you share with people. Amazon::Sites deals with that too. An Amazon associate code is associated with one Amazon site. So the constructor method has an optional “assoc_codes” argument which is a hash mapping country codes to associate codes. If you have set up associate codes in your Amazon::Sites object, then your associate code will be included in any URLs that are generated by the modules – as long as the URL is for one of the sites that you have an associate code for.

That’s all it does at the moment. It addresses most of my needs. There’s one more feature I might add soon. I’d like to have template processing built-in – so if I have a template and an Amazon::Sites object, I can easily process that template for every site that the object knows about.

So that’s the class. I hope someone out there finds it useful. If you think it’s almost useful, but there’s a feature missing then please let me know (or even send a pull request).

But there are a couple of other things I’d like to mention about how I wrote this class.

Firstly, this is written using the new perlclass OO syntax. Specifically, it uses Feature::Compat::Class, so you can use it on versions of Perl back to 5.26. It’s true that the new syntax doesn’t have all the features that you’d get with something like Moose, but I love using it – and over the next few versions of Perl, it will only get better and better. If you haven’t tried the new syntax yet, then I recommend you have a look at it.

Secondly, this is the first new CPAN distribution I’ve written since I’ve had my subscription to GitHub Copilot. And I’m really impressed at how much faster I was using Copilot. As I said, I was using experimental new Perl syntax, so I was impressed at how well Copilot understood what I was doing. I lost count of the number of times I typed the name of a new method and Copilot instantly wrote the code for me – an 95% of the time the code it wrote was spot on. AI programming support is here and it’s good. If you’re not using it yet, then you’re losing out.

I’m told a good blog post needs a “call to action”. This one has three:

  1. Start using Perl’s new class syntax
  2. Look at GitHub Copilot and similar tools
  3. Please use my new module

The post Amazon Links and Buttons first appeared on Perl Hacks.

Hotel hotspot hijinks

perl.com

Published on Tuesday 26 March 2024 18:00

Ever been staying at a hotel and gotten annoyed that you always have to open a browser to log in for wireless access? Yup, me too. A recent instance was particularly frustrating and I had to pull out my favourite Swiss Army chainsaw in order to make my life a bit easier.

The situation

So, the background story is that I was staying at a hotel in the mountains for a few days. As is the fortunate case these days1, the hotel had wireless access. The weird part, though, was that each room had a separate username and password. “Fair enough”, I thought and promptly opened my laptop and then Firefox to enter my login data to get the dearly-awaited connectivity. Using Firefox (or any other browser for that matter) was necessary because the login page was accessed via a captive portal. That’s the thing you get directed through when you see a login banner like this pop up in your browser:

Firefox captive portal login banner

That’s fine, I thought, and went merrily on with my day.

The problem

The problem started the following day. After getting up and waking up my laptop, I wasn’t able to read my email2, or read chat on irc3, see my messages via Signal, or use the internet at all4.

Also, ping greeted me with Destination Net Prohibited:

$ ping www.heise.de
PING www.heise.de (193.99.144.85) 56(84) bytes of data.
From logout.hotspot.lan (192.168.168.1) icmp_seq=1 Destination Net Prohibited
From logout.hotspot.lan (192.168.168.1) icmp_seq=2 Destination Net Prohibited
From logout.hotspot.lan (192.168.168.1) icmp_seq=3 Destination Net Prohibited
^C
--- www.heise.de ping statistics ---
3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2002ms

Obviously, I wasn’t online.

That’s when I noticed the Firefox captive portal login banner (see image above) again. Oh, I have to log in again, that’s weird. Upon clicking on the “Open Network Login Page” button, I was logged in automatically. No need to enter the login details again. That’s also weird, I thought, because if the login is automatic, why do I have to visit the login page again at all?

I put my laptop to sleep to go for a walk around the village, get some groceries, and enjoy the mountain air5. Upon my return, I had to log in again to get wireless access. I was slowly starting to get a bit miffed. My guess is that the MAC address from the relevant end-user device is removed from the access list fairly quickly, perhaps on the order of an hour or two6, and thus network connectivity is cut rather promptly.

One issue that made my situation even worse is that I often have several browser windows open at the same time; usually because I have several trains of thought on the go at once and each window contains information relevant to each train of thought. The thing is, only one of the browser windows actually shows the (automatically appearing) captive portal login banner. Finding the window with the banner was rather time consuming.

Ok, this was starting to get silly and a bit annoying. Time to automate the annoyance away. WWW::Mechanize to the rescue!

WWW::Mechanize as a comic book super hero; generated by DALL-E
WWW::Mechanize as a comic book super hero; generated by DALL-E.

The solution

Why choose WWW::Mechanize? Well, I’ve got experience with it (I used to use a similar process to automatically log in to the ICE train in Germany when I used to commute to work before the pandemic), I know I can use it to submit data into simple HTML forms, and Perl is my go-to language for this kind of automation.

So, how to get started with automating the login process? The simple solution: quit Firefox so that all browser windows are closed, put the computer to sleep and then go for a walk for a couple of hours.

Upon my return, I just needed to use a combination of perl -de0 to start a REPL-like environment to play around in and perldoc to read the extensive WWW::Mechanize documentation.

The first attempt at trying to trigger a connection to the captive portal didn’t go well:

└> perl -de0

Loading DB routines from perl5db.pl version 1.55
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(-e:1):   0
  DB<1> use WWW::Mechanize;

  DB<2> $mech = WWW::Mechanize->new;

  DB<3> $mech->get('https://google.com');

Error GETing https://google.com: Can't connect to google.com:443 (SSL
connect attempt failed) at (eval
22)[/home/cochrane/perl5/perlbrew/perls/perl-5.30.1/lib/5.30.1/perl5db.pl:738]
line 2.

Ok, so we need to use HTTP and avoid HTTPS. Good to know.

Just using HTTP worked much better:

  DB<4> x $mech->get('http://google.com')
0  HTTP::Response=HASH(0x55a95f5048c0)
<snip>
lots of details; you really don't want to see this
</snip>

That’s what we like to see! We’re at least getting stuff back now. Having a look at the page’s title, we get:

  DB<5> x $mech->title();
0  'myadvise hotspot > login'

Yup, that’s a login page. Dumping the page’s content with

  DB<5> x $mech->content();
<snip>
lots of HTML content
</snip>

we get to see what we’ve got to play with. The main things to note about the content (which I’m not showing because it’s too much detail and I want to protect the innocent) are:

  • we have a form called login

    <form name="login" action="http://login.hotspot.lan/login" method="post">
  • we have a username field with the name username

    <input style="width: 80px" name="username" type="text" value=""/>
  • and we have a password field with the name password

    <input style="width: 80px" name="password" type="password"/>

This gives us enough information to be able to submit the form using the relevant login data.

Aside: interestingly enough, the fields are in English even though the site is a German one. I guess standardising the fields on English can be useful when programming.

To submit the form, we use WWW::Mechanize’s submit_form() method (the call to which I’ve formatted nicely here to make things easier to read):

$mech->submit_form(
    form_name => 'login',
    fields => {
        username => 'username-for-room',
        password => 'password-for-room',
    }
);

We can check if the form submission was successful by asking the HTTP::Response if things went well:

  DB<7> x $mech->res->is_success;
0  1

Looking good so far. Let’s see if ping works as expected

$ ping www.heise.de
PING www.heise.de (193.99.144.85) 56(84) bytes of data.
64 bytes from www.heise.de (193.99.144.85): icmp_seq=1 ttl=247 time=20.6 ms
64 bytes from www.heise.de (193.99.144.85): icmp_seq=2 ttl=247 time=13.9 ms
^C
--- www.heise.de ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 13.941/17.281/20.621/3.340 ms

Yes! In other words: we’re in! That was easy. ☺

Putting everything together (and cleaning up the code a bit), I ended up with this:

use strict;
use warnings;

use WWW::Mechanize;

my $mech = WWW::Mechanize->new;
$mech->get('http://google.com');

# check that we have the login page and not Google or something else
# i.e. we're not logged in
if ($mech->title() =~ 'login') {
    $mech->submit_form(
        form_name => 'login',
        fields => {
            username => '<username-for-room>',
            password => '<password-for-room>'
        }
    );
    if ($mech->res->is_success) {
        print "Login successful\n";
    }
    else {
        print "Login failed\n";
    }
}
else {
    print "Already logged in\n";
}

Now I can just run the script every time I wake my laptop back up and I’m back online. Yay!

From a security perspective it’s a bit weird that the username and password are obviously tied to the room number. In other words, I could probably use the neighbouring room’s account just as easily (I guess: I couldn’t be bothered checking in the end).

The conclusion

Well, this script certainly saved me some time and hassle when waking up my laptop from the suspend state. Also, it was fun working out what pieces of the puzzle were necessary in order to build a solution. Perl saves the day7 again!

Originally posted on https://peateasea.de.


  1. Remember when finding a hotel with any wireless connectivity was a total mission? Sort of like the days when finding a power outlet at an airport to charge a laptop was really difficult and one ended up sitting on the floor next to a utility room where the cleaning staff would normally plug in a vacuum cleaner. Ah, those were the days 😉. Put another way: humanity has come a looong way. [return]
  2. I use mutt; it’s fast and one only needs to use text for email. Right? Right? [return]
  3. I also use irssi for IRC. Look, I’ve been around a while, ok? [return]
  4. I’m one of those geeks who live on the terminal, hence I tend to use a lot of terminal-based tools to get things done. [return]
  5. I don’t mean this ironically: because of the forests and the distance away from any kind of metropolis, the air is much fresher. Ever notice that the air in European cities is just awful? [return]
  6. Later, I’d tried putting my computer to sleep and then waking it up a few minutes later. The connection was still alive, so my best guess is that the timeout to keep connections alive and keep a MAC address registered is on the order of hours, but not more than two or three hours, because even such short periods of inactivity required login again. A later test showed that the timeout was after one hour. [return]
  7. Well, it saved the week really. [return]

5 Reasons to Sponsor the Perl Toolchain Summit

perl.com

Published on Monday 25 March 2024 18:00

Photo © Salve J. Nilsen, 2023, CC-BY-NC-4.0

TL;DR Please read and share the prospectus for the Perl Toolchain Summit.

It’s that time of year again. In a few weeks, dozens of Perl hackers will be meeting in Lisbon, Portugal to hack furiously on the Perl Toolchain. I will be there as well, working on MetaCPAN. Most of the other core MetaCPAN developers will be there as well, as is the case most years. We get lots of work done. I usually blog about it. To get an idea of what goes on, you can check out my 2023 Perl Toolchain Summit report and Salve J. Nilsen’s photos.

The summit is a great opportunity for your company to get involved and support the Perl community. Here are 5 reasons why you should sponsor the Perl Toolchain Summit.

1) Synchronous Communication

The developers who maintain CPAN and its associated tools and service are scattered all across the globe and, more importantly, in different time zones. Most of us know that it’s entirely possible to get things done at our day jobs while working remotely. It’s not always this easy when trying to co-ordinate the time, efforts and schedules of volunteers. The Perl Toolchain Summit is the only time of the year when most of these developers are in the same room together. The event gives them the luxury of synchronous, rather than asynchronous communication. Imagine walking across the room to talk to someone rather than waiting for someone who lives across an ocean to find the free time to respond to a GitHub issue or a chat message. Problems can be solved much faster when you get so many stakeholders and decision makers in the same room.

2) Face Time

We also know that communication can be hard and it doesn’t necessarily get easier when much of it happens by text. Giving the Toolchain developers the chance to work face to face means they have a greater understanding and appreciation of whom they are dealing with. The cameraderie which develops at this event allows the Toolchain developers to communicate freely and well when they’re not all together. I’m amazed at how well everyone gets along for the part of the year when we’re not in the same room. It’s a very special group of people.

3) Consensus

Some big decisions require consensus. Consensus requires getting input from many people. Being able to call a meeting to discuss topic X with all of the relevant people is kind of a big deal. Past toolchain summits have given us documents which offer a guide on how to move forward. The Lancaster Consensus is such a document.

4) Distraction-free Time

Most Open Source developers are juggling a bunch of things in their day to day lives and hacking on software is just one of those things. Many of us rarely get more than a few hours in a given week to work distraction-free on something which interests us. Sometimes we don’t even have that luxury. The Toolchain summit gives developers 3-4 days of time to keep barreling ahead on critical software. Imagine what you could do with a hobby project when all you had to worry about was getting up in the morning, having a prepared meal and then plugging in your laptop and consulting the experts sitting around you? That’s exactly what this event is like. It also has the side effect of increasing the cadence of a project in the weeks leading up to the Toolchain where everyone prepares ahead of time, in order to maximize their creativity upon arrival.

5) It Keeps the Toolchain Moving Forward

The Perl Toolchain Summit works to ensure that the parts of the Perl Ecosystem which developers (and businesses) around the world rely on, are cared for. Some problems are thorny. They require time. They require expertise. They require help and possibly a shoulder to cry on. If your business relies on Perl, then it relies on the toolchain. It relies on a healthy and secure ecosystem. These are critical things, but they’re also boring. They’re not flashy new apps. They’re not going to get you on the front page of Hacker News. They are, however, going to allow people and businesses around the world to carry on with their lives, blissfully unaware of the efforts which are going into the software which underpins some part of their existence. Sponsoring this event allows you to support the boring, important parts of Perl.

By now you’re probably thinking “shut up and take my money”. That’s wonderful! Sponsoring the event is easy. Please have a look at the prospectus. It has more information on this event and it has everything you need to get started as a sponsor. Kindly pass the prospectus along to your friends and colleagues and together we can work together to keep the Perl Toolchain moving forward.

Some app I work on needs to export some data and send it to customers in a traceable way. We need to make sure that we keep track of each filename, and also make sure that the customers can (maybe even months later) tell us which export file might need some handling. So we decided to use a rather verbose filename containing the customer name, a timestamp and the uuid of the export job eg export_some_customer_2024-03-25T16:20:12_fcdc290d-50cb-403d-981d-51c8e871.zip.

Generating and sending such a mail is quite easy using eg Email::Stuffer and Email::Sender::Simple:

 my $filename = 'export_some_customer_2024-03-25T16:20:12_fcdc290d-50cb-403d-981d-51c8e871.zip';
    
    my $email = Email::Stuffer
       ->to(          $customer_email )
       ->cc(          $our_archive_email )
       ->from(        $sender )
       ->subject(     "Your data" )
       ->text_body(   "Please find your data attached" )
       ->attach_file( $filename )
       ->email;
    
    Email::Sender::Simple->send( $email, { transport => $smtp } );

I tested this using a local maildev and also via google mail (as we're using that for that project..). It also worked for the customers. Well, some customers...

PEBCAK?

One customer complained that they could not open the file (on Windows). The file actually is a password "protected" zip archive containing a CSV, so I assumed they had some problems with that setup and provided some detailed instruction on how to open / extract that file and make sure that Windows does not mangle the extensions etc. The customer was satisfied. I grumbled a bit about Windows and customers and went on to do other stuff.

Some time later, due to some stupidity on my part, we sent out that file as a regular CSV file (without packing it into zip). Again, the customer complained that they could not unpack the file after downloading it and adding a zip extension. That's when I started to wonder what was really going on, because I got the mail as a plain CSV file and never should the customer need to manually add an extension.

And what going on was that the customer did not get any file extensions, just a plain string, then manually added the (in that case wrong) extension zip and only then could proceed. And the customer was not using gmail, but something else.

So I tried to open the mail in mutt, and .. the attachment was indeed mangled: The filename was truncated, the extension missing.

Headers

This prompted a closer examination of the mail headers:

Content-Type: application/octet-stream;
   name*0=export_some_customer_2024-03-25T16:20:12_fcdc290d-50cb-403d-981d-51c8;
   name*1=e871.zip
   name=export_some_customer_2024-03-25T16:20:12_fcdc290d-50cb-403d-981d-51c...

Ouch!

It seems that some part of the (40 years old?) email spec cannot handle long filenames, therefore they are broken into multiple lines.

And it seems that some mail clients can handle this multi line filenames, and some cannot handle them (among them mutt, which I find sad, but in this case lucky, because I'm not sure I would ever found the real bug and just assumed customer incompetence...)

Fix it

The fix was of course easy: pack the actual file (with the still long and very verbose filename) into a zip archive with a different, much shorter name.

But it was still interesting to learn that in that case the problem was not a stupid customer or an annoying OS, but the fact the email obviously needs to printable on a dot-matrix printer and therefor should not have more than 80 characters per line...

Update: dakkar pointed out the relevant RFC 2332, Section 3.

The examples used here are from the weekly challenge problem statement and demonstrate the working solution.

File Index

"ch-1.pl" Defined by 1.

"ch-2.pl" Defined by 7.

Part 1: Element Digit Sum

You are given an array of integers, @integers. Write a script to evaluate the absolute difference between every element and the digit sum of the entire given array.

The complete solution is contained in one file that has a simple structure.

"ch-1.pl" 1


preamble 2
element digit sum 5
main 6

For this problem we do not need to include very much. We’re just specifying to use the current version of Perl, for all the latest features in the language. This fragment is also used in Part 2.

preamble 2 ⟩≡


use v5.38;

Fragment referenced in 1, 7.

First, let’s consider how we compute the digit sum for an array of integers. If we we make sure that all multi-digit numbers are expanded into lists of digits then this is the sum of the concatenation of all such lists, along with single digit numbers.

The expansion of multi-digit numbers is handled by map, and the sum is taken with unpack and the resulting final array. A key thing to remember here is that Perl will flatten all lists inside the array so all the results from the map will be in a list of single digits.

compute digit sum 3 ⟩≡


my $digit_sum = unpack(q/%32I*/, pack(
q/I*/, map {split //, $_} @{$integers})
);

Fragment referenced in 5.

Defines: $digit_sum 5.

Uses: $integers 5.

The element sum is the same procedure as the digit sum, but just without the map.

compute element sum 4 ⟩≡


my $element_sum = unpack(q/%32I*/, pack q/I*/, @{$integers});

Fragment referenced in 5.

Defines: $element_sum 5.

Uses: $integers 5.

element digit sum 5 ⟩≡


sub element_digit_sum{
my($integers) = [@_];
compute digit sum 3
compute element sum 4
return abs($element_sum - $digit_sum)
}

Fragment referenced in 1.

Defines: $integers 3, 4.

Uses: $digit_sum 3, $element_sum 4.

Finally, we have a few lines of code for running some tests.

main 6 ⟩≡


MAIN:{
say element_digit_sum 1, 2, 3, 45;
say element_digit_sum 1, 12, 3;
say element_digit_sum 1, 2, 3, 4;
say element_digit_sum 236, 416, 336, 350;
}

Fragment referenced in 1.

Sample Run
$ perl perl/ch-1.pl 
36 
9 
0 
1296
    

Part 2: Multiply by Two

You are given an array of integers, @integers and an integer $start. Write a script to do the following:

a) Look for $start in the array @integers, if found multiply the number by 2.

b) If not found stop the process, otherwise repeat.

In the end return the final value.

We’ll contain the solution in a single recursive function. The completed solution will just have that function plus a few tests.

"ch-2.pl" 7


preamble 2
search and multiply 8
main 9

This is our principal function. As can be seen, it’s very short! The logic here is simple: for each recursive call check for $start in the array and, if found, double $start and keep recursing. Otherwise, return $start.

search and multiply 8 ⟩≡


sub search_multiply{
my($start) = shift;
return $start if 0 == grep {$start == $_} @_;
search_multiply($start + $start, @_);
}

Fragment referenced in 7.

Finally, here’s a few tests to confirm everything is working right.

main 9 ⟩≡


MAIN:{
say search_multiply 3, 5, 3, 6, 1, 12;
say search_multiply 1, 1, 2, 3, 4;
say search_multiply 2, 5, 6, 7;
}

Fragment referenced in 7.

Sample Run
$ perl ch-2.pl 
24 
8 
2
    

References

The Weekly Challenge 261
Generated Code