Hello,
I'm trying to install Request Tracker and in the process am receiving an error that states:
Some dependencies were missing:
DBD::mysql >= 2.1018, != 4.042 ................... MISSING
I'm lost. How to do I resolve this?
Thank you!
Published by khwilliamson on Tuesday 15 October 2024 16:28
regexec.c: Remove no-value-added function This function merely calls an inline one. Might as well not have any indirection.
Published by /u/mr_chromatic on Tuesday 15 October 2024 16:20
Did anyone else receive unsolicited email from the Science Perl Committee announcing a journal for sale? I'm not sure how or why they added my email address to the list. It'd be interesting to see if others also did so.
Published by Nilesh on Tuesday 15 October 2024 15:21
We are using WWW::Mechanize to send json data to our api.
My code is below.
#!/usr/local/bin/perl
use WWW::Mechanize;
sub get_csrf_token {
my $sso = shift;
my $referer = shift;
my @cookie_items;
my $rsp = $sso->get($referer);
my $set_cookie = $rsp->header('set-cookie');
if ($set_cookie =~ /csrftoken=(\S+);/) {
push(@cookie_items, $1);
}
if ($set_cookie =~ /sessionid=(\S+);/) {
push(@cookie_items, $1);
}
else {
die 'Failed to get CSRF Token';
}
return @cookie_items;
}
my $sso = WWW::Mechanize->new(
keep_alive => 0,
timeout => 3000,
stack_depth => 1,
debug => 1,
verbose => 1,
key => "/home/user/.athenz/key",
cert => "/home/user/.athenz/cert",
);
my $referer = "https://myapi.domain.com/athenz/api/healthcheck/";
my @cookies = get_csrf_token($sso, $referer);
$sso->add_header('Referer' => $referer);
$sso->add_header('X-CSRFToken' => $cookies[0]);
$sso->add_header('Cookie' => "sessionid=$cookies[1]; csrftoken=$cookies[0]");
my %content = (
'value' => '127.0.0.1',
'key_name' => 'NTP_SERVERS'
);
my $response = $sso->put("https://myapi.domain.com/athenz/api/NTP_SERVERS/", \%content);
print "^^^^^^^^^^^^^^^^^^^^^^^^^\n";
print $response->code();
print "\n^^^^^^^^^^^^^^^^^^^^^^^^^\n";
its give me error Error PUTing https://myapi.domain.com/athenz/api/NTP_SERVERS/: Bad Request at /tmp/test.pm line 53
When I check server logs, its seems, the payload which I am sending, is deliver to server as HASH
instead of json.
Below is apache logs.
[Mon Oct 07 18:32:27.987189 2024] [ssl:info] [pid 19745:tid 19745] [client 127.0.0.1:58372] AH01964: Connection to child 29 established (server myapi.domain.com:443)
[Mon Oct 07 18:32:27.987600 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [init-blocking] 0 readbytes
[Mon Oct 07 18:32:27.987964 2024] [ssl:debug] [pid 19745:tid 19745] ssl_engine_kernel.c(2393): [client 127.0.0.1:58372] AH02043: SSL virtual host for servername myapi.domain.com found
[Mon Oct 07 18:32:27.992817 2024] [ssl:debug] [pid 19745:tid 19745] ssl_engine_kernel.c(2256): [client 127.0.0.1:58372] AH02041: Protocol: TLSv1.2, Cipher: ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)
[Mon Oct 07 18:32:27.992936 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:32:27.993929 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(63): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): 53 bytes
[Mon Oct 07 18:32:27.993964 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(103): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): PUT /athenz/api/NTP_SERVERS/ HTTP/1.1
[Mon Oct 07 18:32:27.994033 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:32:27.994047 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(63): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): 24 bytes
[Mon Oct 07 18:32:27.994056 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(103): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): TE: deflate,gzip;q=0.3
[Mon Oct 07 18:32:27.994065 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:32:27.994089 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(63): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): 23 bytes
[Mon Oct 07 18:32:27.994093 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(103): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): Connection: TE, close
[Mon Oct 07 18:32:27.994100 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:32:27.994104 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(63): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): 23 bytes
[Mon Oct 07 18:32:27.994123 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(103): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): Accept-Encoding: gzip
[Mon Oct 07 18:32:27.994127 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:32:27.994132 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(63): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): 45 bytes
[Mon Oct 07 18:32:27.994135 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(103): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): Host: myapi.domain.com
[Mon Oct 07 18:32:27.994139 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:32:27.994143 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(63): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): 84 bytes
[Mon Oct 07 18:32:27.994147 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(103): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): Referer: https://myapi.domain.com/athenz/api/healthcheck/
[Mon Oct 07 18:32:27.994151 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:32:27.994155 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(63): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): 32 bytes
[Mon Oct 07 18:32:27.994158 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(103): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): User-Agent: WWW-Mechanize/1.72
[Mon Oct 07 18:32:27.994185 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:32:27.994190 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(63): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): 128 bytes
[Mon Oct 07 18:32:27.994193 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(103): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): Cookie: sessionid=XXXXXXX; csrftoken=YYYYYYY
[Mon Oct 07 18:32:27.994198 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:32:27.994201 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(63): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): 19 bytes
[Mon Oct 07 18:32:27.994205 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(103): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): HASH(0x1d5b760):
[Mon Oct 07 18:32:27.994209 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(140): [client 127.0.0.1:58372] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:32:27.994213 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(63): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): 79 bytes
[Mon Oct 07 18:32:27.994217 2024] [dumpio:trace7] [pid 19745:tid 19745] mod_dumpio.c(103): [client 127.0.0.1:58372] mod_dumpio: dumpio_in (data-TRANSIENT): X-CSRFToken: YYYYYYY
[Mon Oct 07 18:32:27.994223 2024] [core:debug] [pid 19745:tid 19745] protocol.c(1290): [client 127.0.0.1:58372 {YRA:127.0.0.1:58372, YPA:127.0.0.1:58372}] AH02426: Request header field name is malformed: HASH(0x1d5b760):, referer: https://myapi.domain.com/athenz/api/healthcheck/
[Mon Oct 07 18:32:27.994328 2024] [core:debug] [pid 19745:tid 19745] protocol.c(1482): [client 127.0.0.1:58372 {YRA:127.0.0.1:58372, YPA:127.0.0.1:58372}] AH00567: request failed: error reading the headers, referer: https://myapi.domain.com/athenz/api/healthcheck/
If I use same API with curl, it works fine and apache logs gives no error.
curl --cert ~/.athenz/cert --key ~/.athenz/key -H "Content-type: application/json" -H "X-CSRFToken: $TOKEN" --referer "https://myapi.domain.com/athenz/api/healthcheck/" --cookie "csrftoken=$TOKEN;sessionid=$SESSIONID;" "https://myapi.domain.com/athenz/api/NTP_SERVERS/" -X PUT -d '{"key_name": "NTP_SERVERS", "value": "98.139.133.27"}' -i
HTTP/1.1 200 OK
Date: Mon, 07 Oct 2024 18:26:50 GMT
P3P: policyref="https://policies.domain.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
Allow: GET, PUT, DELETE, HEAD, OPTIONS
X-Frame-Options: DENY
Vary: Cookie
Content-Length: 0
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
Access-Control-Allow-Credentials: true
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Set-Cookie: csrftoken=YYYYYYYYYYY; Domain=.domain.com; expires=Mon, 06 Oct 2025 18:26:53 GMT; Max-Age=31449600; Path=/; SameSite=Lax
Set-Cookie: sessionid=XXXXXXXXXXXX; expires=Mon, 21 Oct 2024 18:26:53 GMT; HttpOnly; Max-Age=1209600; Path=/; SameSite=Lax
Cache-Control: private
Connection: close
The apache logs, which print the json I passed in the curl.
[Mon Oct 07 18:26:50.576736 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:26:50.935742 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 53 bytes
[Mon Oct 07 18:26:50.935767 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): PUT /athenz/api/NTP_SERVERS/ HTTP/1.1
[Mon Oct 07 18:26:50.935821 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:26:50.935840 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 31 bytes
[Mon Oct 07 18:26:50.935844 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): Host: myapi.domain.com
[Mon Oct 07 18:26:50.935848 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:26:50.935852 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 24 bytes
[Mon Oct 07 18:26:50.935857 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): User-Agent: curl/8.7.1
[Mon Oct 07 18:26:50.935863 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:26:50.935867 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 13 bytes
[Mon Oct 07 18:26:50.935871 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): Accept: */*
[Mon Oct 07 18:26:50.935875 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:26:50.935880 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 43 bytes
[Mon Oct 07 18:26:50.935883 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): Referer: https://myapi.domain.com/api/healthcheck/
[Mon Oct 07 18:26:50.935887 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:26:50.935890 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 128 bytes
[Mon Oct 07 18:26:50.935894 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): Cookie: csrftoken=YYYYYYYY;sessionid=XXXXXXX;
[Mon Oct 07 18:26:50.935908 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:26:50.935913 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 32 bytes
[Mon Oct 07 18:26:50.935917 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): Content-type: application/json
[Mon Oct 07 18:26:50.935922 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:26:50.935926 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 79 bytes
[Mon Oct 07 18:26:50.935930 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): X-CSRFToken: YYYYYYYYY
[Mon Oct 07 18:26:50.935934 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:26:50.935937 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 20 bytes
[Mon Oct 07 18:26:50.935942 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): Content-Length: 91
[Mon Oct 07 18:26:50.935946 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [getline-blocking] 0 readbytes
[Mon Oct 07 18:26:50.935949 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 2 bytes
[Mon Oct 07 18:26:50.935953 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT):
[Mon Oct 07 18:26:50.937521 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(140): [client 127.0.0.1:57073] mod_dumpio: dumpio_in [readbytes-blocking] 91 readbytes
[Mon Oct 07 18:26:50.937532 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(63): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): 91 bytes
[Mon Oct 07 18:26:50.937537 2024] [dumpio:trace7] [pid 19725:tid 19725] mod_dumpio.c(103): [client 127.0.0.1:57073] mod_dumpio: dumpio_in (data-TRANSIENT): {"key_name": "NTP_SERVERS", "value": "98.139.133.27"}
[Mon Oct 07 18:26:50.937558 2024] [ssl:info] [pid 19725:tid 19725] [client 127.0.0.1:57073 {YRA:127.0.0.1:57073, YPA:127.0.0.1:57073}] AH02221: Requesting connection re-negotiation, referer: https://myapi.domain.com/api/healthcheck/
How can I make sure, perl script pass json
data to the apache server? I tried setting Content-Type: application/json
, that didnt work.
Published by khwilliamson on Tuesday 15 October 2024 14:54
perlapi: Rmv extraneous minus sign
Published by /u/briandfoy on Tuesday 15 October 2024 14:25
Published by smith on Tuesday 15 October 2024 14:01
I am running this snippet of code from the module synopsis using strawberry Perl :
use Mojolicious::Lite;
# Because the route name "echo" matches the "x-mojo-name", this route
# will be moved under "basePath", resulting in "POST /api/echo"
post "/echo" => sub {
# Validate input request or return an error document
my $c = shift->openapi->valid_input or return;
# Generate some data
my $data = {body => $c->req->json};
# Validate the output response and render it to the user agent
# using a custom "openapi" handler.
$c->render(openapi => $data);
}, "echo";
# Load specification and start web server
plugin OpenAPI => {url => "data:///swagger.yaml"};
app->start;
__DATA__
@@ swagger.yaml
swagger: "2.0"
info: { version: "0.8", title: "Echo Service" }
schemes: ["https"]
basePath: "/api"
paths:
/echo:
post:
x-mojo-name: "echo"
parameters:
- { in: "body", name: "body", schema: { type: "object" } }
responses:
200:
description: "Echo response"
schema: { type: "object" }
Then run the script as a daemon which listen on port 3000 after that i am running Curl as the below from the same machine
curl -X POST http://127.0.0.1:3000/api/echo -H "Content-Type : application/json" -d "{ \"key\" : \"value\" }"
my expection to render the __DATA__
section but i am getting this error
{"errors":[{"message":"Expected - got *\/*.","path":"\/header\/Accept"}],"status":400}
any idea what could be the problem ?
submitted by /u/oalders [link] [comments] |
submitted by /u/oalders [link] [comments] |
Published by horshack on Tuesday 15 October 2024 11:08
Windows, Visual Studio Code. I have installed the extension: "Perl Navigator" and perl is installed in my computer system, perltidy is installed. The code in a file is like this:
#!/usr/bin/perl
use strict;
use warnings ;
use Params::Validate;
my $x =4;
my $y = "AB";
What can I do to reformat this code with perltidy with Visual Studio Code?
In vim I do this:
ESC :1,$!perltidy
I installed several extensions for Visual Studio Code but none of these tell me how to use them.
Published by iabyn on Tuesday 15 October 2024 09:49
fix authors after previous commit
Published by book on Monday 14 October 2024 17:53
clarify the comparison between 'our' and 'use vars' Fixes GH #22424
Published by London Perl Workshop on Monday 14 October 2024 15:55
This year's London Perl and Raku Workshop will take place on 26th Oct 2024. Without our sponsors this event would not happen and we would like to thank them.
Since its founding in 2000, CV-Library has relied on Perl as the backbone of its core operations. Today, as the UK’s leading independent job board, we host over 150,000 job postings and maintain a database of more than 20 million CVs.
For nearly 25 years, CV-Library has been a committed supporter of LPW and the Perl community. We're proud to reaffirm this dedication at the 2024 conference.
Our platform now integrates modern Perl with Go, leveraging Kubernetes for scalable deployments, alongside other cutting-edge technologies to ensure stability and reliability.
Our development team consistently delivers high-quality features through code reviews, automated tests, and continuous deployment. Additionally, we regularly contribute to free and open-source projects, including CPAN.
CV-Library offers remote opportunities for developers and testers at all levels. We encourage participation in community meetups and collaboration days. Feel free to introduce yourself to Mark or any member of our team at the event, or explore our current job openings here.
Published by Gabor Szabo on Monday 14 October 2024 06:43
Originally published at Perl Weekly 690
Hi there,
Happy Hacking everyone !!!
I hope you are busy contributing during this year Hacktoberfest. We are half way through already but still plenty of time left to kickstart if not done already.
How about LPW 2024?
Well it is less than 2 weeks before the much awaited London Perl & Raku Workshop 2024 begins the fun. I am very happy to see the support of Perl community in general. It is great to see regular names in the list of sponsors, specially my current employer Oleeo as Gold sponsor. Thank you, Lee Johnson, for all the hardwork, managing the event so smoothly so far. I am confident it would be a memorable event for everyone.
Those who are planning to attend the event, there would be Pre Workshop Social and Post Workshop Social. Please register your details asap. I have once attended pre workshop social in the past as the usual venue is not my favourite spot. Having said, I am planning to break the tradition this year and planning to attend post social workshop. How can I miss the opportunity to meet my techie friends.
Have you seen the favourite talks list?
I am personally looking forward to attend the talks e.g. Perl in 2030, Cloudy Perl, how it looks now, A modern introduction to XS. Also my own talk, What's new in Perl v5.40?. I happy to see the some familiar names shown interest in my talk. I can't wait to present my talk.
I am also looking forward to meet some of my techie friends after a long time. Recently I found out one coming all the way from Canada. I am wondering if anyone coming from Japan. In the past, we always had speaker from Japan. I hope to see the familiar face this time too. Anyone from Germany? We will all find out first thing at the registration desk on the day.
As the October arrived, it also brought the dull weather with it. I don't have good memory about it. I hope it passes without creating any havoc. You take extra care of your health, specially mental and enjoy rest of the newsletter.
--
Your editor: Mohammad Sajid Anwar.
A new module, Weather::ORM just arrived. The OpenWeather API has a Free tier with both current weather and forecast, which makes the module useful to anyone interested in fetching weather for any location.
Olaf Alders joined this week PSC meeting exchanged ideas.
The Open Source Pledge consists of companies with a shared commitment to paying the maintainers of the open source software they consume, therefore aims to help address sustainability challenges facing the Open Source community.
Create a parallel echo server using SPVM::IO::Socket::IP and goroutines, channels, select in SPVM::Go.
Wouldn't you like to output a single executable file from your AI program? Then, you can run the AI program just by copying the executable file to the Raspberry Pi.
This is the beginning of wxPerl revival. Please do support the initiative.
Oleeo is an award-winning provider of innovative talent acquisition technology. Built using intelligent automation and machine learning, Oleeo’s platform helps companies discover unlimited sourcing potential to attract, engage and hire amazing, diverse teams that change the world for the better.
Geekuni can give software developers with no previous Perl experience the training they need, as they need it. Geizhals Preisvergleich is one of the largest product and price comparison platforms in the German-speaking area.
The Weekly Challenge by Mohammad Sajid Anwar will help you step out of your comfort-zone. You can even win prize money of $50 by participating in the weekly challenge. We pick one champion at the end of the month from among all of the contributors during the month, thanks to the sponsor Lance Wicks.
Welcome to a new week with a couple of fun tasks "Middle Index" and "Poker Hand Rankings". 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.
Enjoy a quick recap of last week's contributions by Team PWC dealing with the "Double Exist" and "Luhn's Algorithm" tasks in Perl and Raku. You will find plenty of solutions to keep you busy.
Compact solutions in Perl as always and self explanatory. You really don't want to miss it.
Simple yet elegant approach in Perl and Go. Great work, keep sharing.
Interesting way to deal with edge case using the power of Raku. And on top, get the complete official word on each feature used.
You get nice story to start with and then comes the technical discussion. It is engaging yet, thanks for sharing.
Line-by-line discussion is a cool way to get the end result. Keep it up great work.
As per the tradition, we got side by side implementation in Perl and Raku. Plenty for both fans, keep the tradition alive.
Real life story behind Luhn's algorithm. Thanks for sharing the story with us. Great work.
Simple loop in Raku is enough to get this week task done and self explanatory too. We also have bonus solutions in Java, Python and PostgreSQL.
In-house Perl one-liner expert sharing the quality implementation. Keep it up great work.
Smart use of CPAN to get a compact solution in Perl. Simple love the detailed discussion. Keep sharing the knowledge with us.
Musical background to the weekly challenge is always fun. Following which we get the thorough discussion of implementation in Perl, Raku, Python and Elixir. Highly recommended.
A verbose approach to make it easy to read and follow. DIY tool is the icing on the cake. Well done.
Old school double loops with detailed comments. Keep it up great work.
We got another musical solution. I just love the musical theme. Keep sharing knowledge.
Postscript is one language that I find very fascinating and when we get the detailed narration then it becomes so easy to follow. Highly recommended.
Two in a row, what a pleasant surprise. Thanks for the quality blog post. Please keep sharing.
Like always, the post is dedicated to Python fans. Plenty for Perl fans to learn. Keep it up great work.
Great CPAN modules released last week.
October 24, 2024, Virtual event
October 26, 2024, in London, UK
November 12, 2024, Virtual event
November 13, 2024, Virtual event
You joined the Perl Weekly to get weekly e-mails about the Perl programming language and related topics.
Want to see more? See the archives of all the issues.
Not yet subscribed to the newsletter? Join us free of charge!
(C) Copyright Gabor Szabo
The articles are copyright the respective authors.
Published on Monday 14 October 2024 01:19
The examples used here are from the weekly challenge problem statement and demonstrate the working solution.
You are given an array of integers, @ints. Write a script to find if there exist two indices $i and $j such that:
The majority of the work can be done in a few lines. If there is a more elegant way to do this, it escaped me when I was writing this code!
sub double_exist{
my(
@a) =
@_;
do{
my $i = $_;
do{
my $j = $_;
if($i != $j){
return 1 if $a[$i] == 2 * $a[$j];
}
} for 0 ..
@a - 1;
} for 0 ..
@a - 1;
return 0;
}
◇
Fragment referenced in 2.
The rest of the code just tests this function.
MAIN:{
say double_exist 6, 2, 3, 3;
say double_exist 3, 1, 4, 13;
say double_exist 2, 1, 4, 2;
}
◇
Fragment referenced in 2.
$ perl perl/ch-1.pl 1 0 1
You are given a string $str containing digits (and possibly other characters which can be ignored). The last digit is the payload; consider it separately. Counting from the right, double the value of the first, third, etc. of the remaining digits. For each value now greater than 9, sum its digits. The correct check digit is that which, added to the sum of all values, would bring the total mod 10 to zero. Return true if and only if the payload is equal to the correct check digit.
This can also be done in relatively few lines. There are no real special cases here.
sub luhn{
my($digits) =
@_;
my
@digits = $digits =~ m/([0-9])/g;
my $sum = 0;
my $check = pop
@digits;
{
my $x = pop
@digits;
my $y = pop
@digits;
if(defined $x && defined $y){
$sum += $y + sum_digits 2 * $x;
}
else{
$sum += sum_digits 2 * $x;
}
redo if
@digits;
}
return 1 if 0 == ($sum + $check) % 10;
return 0;
}
◇
Fragment referenced in 7.
For convenience we’ll put the summing of digits for numbers > 10 in a separate function.
sub sum_digits{
my($x) =
@_;
if($x >= 10){
my
@a = split //, $x;
return $a[0] + $a[1];
}
return $x;
}
◇
Fragment referenced in 7.
The rest of the code drives some tests.
MAIN:{
say luhn q/17893729974/;
say luhn q/4137 8947 1175 5904/;
say luhn q/4137 8974 1175 5904/;
}
◇
Fragment referenced in 7.
$ perl perl/ch-2.pl 1 1 0
Published by Phil Goetz on Monday 14 October 2024 03:06
I'm suddenly unable to run any Perl scripts under Cygwin. Every script I try to run crashes like this:
phil@TAICHI /cygdrive/h/bakE/new/virChecked
$ findFiles -s . -t /cygdrive/D/data-comp/text -u /cygdrive/E/new/virChecked/text -d -a .3
Can't load '/home/phil/perl5/lib/perl5/x86_64-cygwin-threads-multi/auto/Win32/File/File.dll' for module Win32::File: No such file or directory at /usr/lib/perl5/5.36/x86_64-cygwin-threads/DynaLoader.pm line 206.
at /usr/local/bin/findFiles line 24.
Compilation failed in require at /usr/local/bin/findFiles line 24.
BEGIN failed--compilation aborted at /usr/local/bin/findFiles line 24.
phil@TAICHI /cygdrive/h/bakE/new/virChecked
$ pushd /home/phil/perl5/lib/perl5/x86_64-cygwin-threads-multi/auto/Win32/File/
~/perl5/lib/perl5/x86_64-cygwin-threads-multi/auto/Win32/File /cygdrive/h/bakE/new/virChecked
phil@TAICHI ~/perl5/lib/perl5/x86_64-cygwin-threads-multi/auto/Win32/File
$ ls -l File.dll
-r-xr-xr-x 1 phil None 178K Jul 14 2021 File.dll*
Sometimes perl won't open File.dll; sometimes it won't open IO.dll. In either case, the DLL is always exactly where Perl is looking for it, with world read privs; but Perl won't load it.
Line 206 of Dynaloader.pm is
my $libref = dl_load_file($file, $flags) or croak("Can't load '$file' for module $module: ".dl_error());
A comment near the start of Dynaloader says:
The load function that dl_load_file() calls may require an absolute pathname.
I can't find where dl_load_file() is defined. It isn't in Dynaloader.pm; and the only module Dynaloader includes is Config, which also doesn't have it, and includes no other files.
I suspect that some Perl module has changed, with the result that dl_load_file doesn't convert Cygwin absolute pathnames to Windows absolute pathnames. I tried reinstalling Perl 5.36.3-1, but it didn't help. I also made a new Cygwin installation and installed Perl 5.40, but it behaved the same way.
Questions:
POSTSCRIPT added October 13: I've gotten a lot of comments, but not one person has yet answered the simple question of whether THEY currently have a working version of Cygwin Perl. Please, someone, if you have a recent Cygwin Perl that still works, say so.
Welcome to “What’s new on CPAN”, a curated look at last month’s new CPAN uploads for your reading and programming pleasure. Enjoy!
Welcome to “What’s new on CPAN”, a curated look at last month’s new CPAN uploads for your reading and programming pleasure. Enjoy!
cat
but prefixes each line with the filenamesprintf
with Term::ANSI::Sprintf (LNATION)Published by Prakash Khandelwal on Sunday 13 October 2024 16:39
I am asking this as perl developer, But i believe this is common for other programming languages as well.
What is the best way to define Global variables used in projects.
One way is to have them in one Module like Global.pm and all modules can use that.
But if later requirement changes than we have to change the value of that variable in Globals.pm
Or we may have to add new Global variables in Globals.pm.
Whereas Object oriented SOLID principle suggest a class should be close for modification but open for extension (via inheritence) ?
SO what is the best way or which design pattern to use to define Global Variables ?
Published by Unknown on Sunday 13 October 2024 13:06
For several years now, development and support of wxPerl, the interface library between Perl and wxWidgets, has stalled. The latest release was based on Perl 5.16 and wxWidgets 2.9.
Meanwhile some active users have made attempts to port wxPerl to newer versions of Perl and wxWidgets, with varying results. Microsoft Windows and Apple macOS provide additional challenges.
I believe in user-friendly desktop based GUI applications written in Perl and wxPerl is an excellent tool to develop these applications that are deployable across different desktop platforms. I hate to see wxPerl rusting away in the archives.
If you are using wxPerl and want to keep using it with recent
versions of Perl and wxWidgets, please join the mailing list.
As a start, I've set up a new, independent repo for wxPerl on GitHub.
It currently has two branches: wx30 and master.
Branch wx30 contains an updated version of the last 'official' release 0.9932, fixed for modern Perl and wxWidgets 3.0. I have released it on GitHub as Wx-0.9933.
The master branch has been updated with all necessary changes for wxWidgets 3.2. Also some constants and methods have been added to deploy some 3.2 functionality. I have released it on GitHub as Wx-3.001. More will be added in the future but will require help from Perl/XS experts.
Published by Aishik Nath on Saturday 12 October 2024 05:35
Yes, you read that right. Just install Straberry Perl and gcc will be properly installed in your Windows machine.
Each week Mohammad S. Anwar sends out The Weekly Challenge, a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. It's a great way for us all to practice some coding.
You are given an array of integers, @ints
.
Write a script to find if there exist two indices $i
and $j
such that:
This seems relatively straight forward, but there is a massive gotcha that hopefully other Team PWC members also noticed. For this task, I loop through the list and see if a value that is twice its value exist.
However, if the value is '0' (and thus 0 × 2 = 0), I need to check that there were at least two zeros in the list.
def double_exists(ints: list) -> bool:
for i in ints:
if i * 2 in ints:
if i != 0 or ints.count(0) > 1:
return True
return False
$ ./ch-1.py 6 2 3 3
true
$ ./ch-1.py 3 1 4 13
false
$ ./ch-1.py 2 1 4 2
true
$ ./ch-1.py 1 3 0
false
$ ./ch-1.py 1 0 3 0
true
You are given a string $str
containing digits (and possibly other characters which can be ignored). The last digit is the payload; consider it separately. Counting from the right, double the value of the first, third, etc. of the remaining digits.
For each value now greater than 9, sum its digits.
The correct check digit is that which, added to the sum of all values, would bring the total mod 10 to zero.
Return true if and only if the payload is equal to the correct check digit.
I start this task by removing non-digit characters from the string, and turn the reversed string into a list of integers.
I then use the supplied formula, alternating between adding the value to count
or multiplying it by two and removing 9. If the resulting count
is divisible by 10, I return True
, otherwise I return False
.
def luhn_algorithm(s: str) -> bool:
s = re.sub('[^0-9]', '', s)
ints = [int(n) for n in s[::-1]]
count = 0
for pos, i in enumerate(ints):
if pos % 2 == 1:
i *= 2
if i > 9:
i -= 9
count += i
return count % 10 == 0
$ ./ch-2.py 17893729974
true
$ ./ch-2.py "4137 8947 1175 5904"
true
$ ./ch-2.py "4137 8974 1175 5904"
false
Published by André Plöger on Friday 11 October 2024 19:50
In this article, we will address two engaging tasks from the Perl Weekly Challenge #290: checking for double existence in an array and implementing Luhn's Algorithm for validation. We'll implement solutions in both Perl and Go.
The first task involves finding if there exist two indices $i
and $j
such that:
1. $i != $j
2. 0 <= ($i, $j) < scalar @ints
3. $ints[i] = 2 * $ints[j]
Input: An array of integers, @ints
.
Output: true
if the condition is met; otherwise, false
.
Examples:
Input: @ints = (6, 2, 3, 3)
Output: true
For $i = 0, $j = 2
$ints[$i] = 6 => 2 * 3 => 2 * $ints[$j]
Input: @ints = (3, 1, 4, 13)
Output: false
Input: @ints = (2, 1, 4, 2)
Output: true
For $i = 2, $j = 3
$ints[$i] = 4 => 2 * 2 => 2 * $ints[$j]
Perl Implementation
In the Perl implementation, we use a hash to track seen integers and check if either half or double of the current number exists in the hash.
sub double_exist {
my %seen;
foreach my $num (@_) {
return 1 if exists $seen{$num / 2} || exists $seen{$num * 2};
$seen{$num} = 1;
}
return 0;
}
Go Implementation
The Go implementation follows a similar logic, using a map to keep track of unique integers.
func doubleExist(ints []int) bool {
seen := make(map[int]bool)
for _, num := range ints {
if (num%2 == 0 && seen[num/2]) || seen[num*2] {
return true
}
seen[num] = true
}
return false
}
The second task involves implementing Luhn's Algorithm to validate a string of digits, ignoring non-digit characters. The last digit is considered separately as the payload.
You are given a string str
containing digits (and possibly other characters which can be ignored). The last digit is considered as the payload and handled separately.
Return true
if the payload equals the correct check digit; otherwise, return false
.
Examples:
Input: "17893729974"
Output: true
Payload is 4.
Digits from the right:
7 * 2 = 14, sum = 5
9 = 9
9 * 2 = 18, sum = 9
2 = 2
7 * 2 = 14, sum = 5
3 = 3
9 * 2 = 18, sum = 9
8 = 8
7 * 2 = 14, sum = 5
1 = 1
Sum of all values = 56, so 4 must be added to bring the total mod 10 to zero. The payload is indeed 4.
Input: "4137 8947 1175 5904"
Output: true
Input: "4137 8974 1175 5904"
Output: false
Perl Implementation
The Perl implementation processes the input string to ignore non-digit characters, then applies Luhn's algorithm to validate the number.
sub luhn_check {
my ($str) = @_;
$str =~ s/[^0-9]//g;
my $payload = substr($str, -1);
my $sum = 0;
my $length = length($str);
for (my $i = 0; $i < $length - 1; $i++) {
my $digit = substr($str, $length - 2 - $i, 1);
if ($i % 2 == 0) {
$digit *= 2;
$digit -= 9 if $digit > 9;
}
$sum += $digit;
}
my $check_digit = (10 - ($sum % 10)) % 10;
return $payload == $check_digit ? 1 : 0;
}
Go Implementation
The Go version implements the same logic, utilizing the unicode package to filter out non-digit characters.
func luhnCheck(str string) bool {
sum := 0
payload := 0
digits := []int{}
for _, char := range str {
if unicode.IsDigit(char) {
digit := int(char - '0')
digits = append(digits, digit)
}
}
if len(digits) == 0 {
return false
}
payload = digits[len(digits)-1]
for i := 0; i < len(digits)-1; i++ {
digit := digits[i]
if (len(digits)-2-i)%2 == 0 {
digit *= 2
if digit > 9 {
digit -= 9
}
}
sum += digit
}
checkDigit := (10 - (sum % 10)) % 10
return payload == checkDigit
}
In this article, we explored two interesting programming challenges: finding double existence in an array and implementing Luhn's Algorithm for validation. These tasks highlight how different programming languages can tackle similar problems with their own unique approaches. I hope these examples inspire you to delve deeper into both Perl and Go!
You can find the complete code, including tests, on GitHub.
Published by Grinnz on Friday 11 October 2024 15:42
perlfunc - update each documentation with foreach examples Also mention multiple-value foreach as a new alternative, and fix a hash dereference in a previous example.
Published by London Perl Workshop on Friday 11 October 2024 14:30
This year's London Perl and Raku Workshop will take place on 26th Oct 2024. Without our sponsors this event would not happen and we would like to thank them.
Perl developers are hard to get. As the leading language of the dotcom boom, Perl is one of the best-paid languages worldwide, yet Perl training seldom features on university curricula. But that doesn't have to cause a headache for employers trying to expand their Perl team.
Geekuni can give software developers with no previous Perl experience the training they need, as they need it. So, whether you’re looking to provide new recruits with online Perl training from day one of the onboarding process or upskill existing talent, Geekuni has the training package to empower your staff with Perl.
To find out more, go here: https://geekuni.com/corporate-perl-training or email andrew@geekuni.com
Geizhals Preisvergleich is one of the largest product and price comparison platforms in the German-speaking area.
For now over 20 years, our company has proven itself in a highly competitive, dynamic industry.
We attribute our success to an uncompromising implementation of our company philosophy: transparency, objective and user-oriented information, and the quality of our content.
The Geizhals Preisvergleich teach team has been a proud user and supporter of the Perl programming language since the founding of the company. In the last months this includes directly supporting development for the "Corinna in Core" project.
Datensegler e.U. is a small team of Perl enthusiasts specialized in agile software development and PostgreSQL consulting from Vienna, Austria and are happy to sponsor the LPW2024.
We use Perl in the majority of our projects both for web applications (shout-out to the formidable Mojolicious framework) and backend tasks from ETL to web scraping since, well basically forever.
We also offer PostgreSQL consulting, including developer support, optimization and operating. If you want to migrate from Oracle or MySQL to PostgreSQL we can lend a helping hand too.
Founded in 2004 and based in Manchester, SpareRoom is the largest flatmate finding service in the UK and globally. Sharing isn’t just at the heart of our business - it IS our business. We are dedicated to helping people find more than just a room; we help them find the right people to live with and turn their flatshare into their home.
A Perl company from the start, we continue to enhance our services using modern Perl, thanks to our small but talented team of seasoned Perl developers and our commitment to training junior developers as they embark on their Perl journey. We are usually on the lookout for Perl talent, so feel free to contact us through our jobs page.
Our commitment to Perl and open-source software is strong. You can often find our team members either attending or speaking at Perl events, or contributing to CPAN and other open-source projects. Thus, we are proud to sponsor the London Perl Workshop as it makes its return, an event we have eagerly awaited and supported.
Published by Perl Steering Council on Friday 11 October 2024 04:21
We had a guest this week: Olaf Alders.
Published by laurent_r on Friday 11 October 2024 03:20
These are some answers to the Week 290, 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 October 13, 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.
You are given an array of integers, @ints
.
Write a script to find if there exist two indices $i
and $j
such that:
1) $i != $j
2) 0 <= ($i, $j) < scalar @ints
3) $ints[$i] == 2 * $ints[$j]
Example 1
Input: @ints = (6, 2, 3, 3)
Output: true
For $i = 0, $j = 2
$ints[$i] = 6 => 2 * 3 => 2 * $ints[$j]
Example 2
Input: @ints = (3, 1, 4, 13)
Output: false
Example 3
Input: @ints = (2, 1, 4, 2)
Output: true
For $i = 2, $j = 3
$ints[$i] = 4 => 2 * 2 => 2 * $ints[$j]
I initially didn't understand condition (2). This ($i, $j)
expression didn't make sense to me, until I understood that it meant that both $i
and $j
have to be greater than or equal to zero, and smaller than the number of items in the array.
Note that the first condition, $i != $j
, is unnecessary since, if $i == $j
, then we cannot meet condition (3), $ints[$i] == 2 * $ints[$j]
. Well, that is except if the value is 0, but zeros should be avoided anyway because we could have 0 = 2 * 0
, which is technically true, but that's not really the meaning of the task. I'll therefore consider that the input should be an array of non-zero integers because what we should do with the zero special case is unclear and not specified in the task. Thus, there is no need to check condition (1) in our code (this applies only to the Perl implementation, as we don't have this issue with the Raku implementation).
In Raku, the built-in combinations routine make it possible to generate automatically all combinations of two items of an array. Combinations are unordered. In other words, with an input such as <1 2 3>
, the combinations
method will generate the following combinations: (1 2) (1 3) (2 3)
, but not (2, 1)
, (3, 1)
, or (3, 2)
. Therefore, for each combination, we need to compare both ways: is the first item the double of the second, and is the second item the double of the first.
sub double-exists (@in) {
for @in.combinations: 2 -> $comb {
return True if $comb[0] == 2 * $comb[1] or
$comb[1] == 2 * $comb[0];
}
False;
}
my @tests = <1 2 3 4>, <6 2 3 3>, <3 1 4 13>, <2 1 4 2>;
for @tests -> @test {
printf "%-10s => ", "@test[]";
say double-exists @test;
}
This program displays the following output:
$ raku ./double-exists.raku
1 2 3 4 => True
6 2 3 3 => True
3 1 4 13 => False
2 1 4 2 => True
Perl doesn't have a built-in combinations
subroutine, so we will apply the canonical method of generating them (as well as those reversing the value order) using two nested loops. Please read my comments at the beginning of this post concerning the first condition ($i != $j
) and the need to avoid zero values in the input. If you disagree with my view, it is very easy to add a code list such as:
next if $i == $j;
in the inner loop of the code below.
sub double_exists {
for my $i (0..$#_) {
for my $j (0..$#_) {
return "True" if $_[$i] == 2 * $_[$j];
}
}
return "False";
}
my @tests = ( [1, 2, 3, 4], [6, 2, 3, 3 ],
[3, 1, 4, 13], [2, 1, 4, 2] );
for my $test (@tests) {
printf "%-10s => ", "@$test";
say double_exists @$test;
}
This program displays the following output:
$ perl ./double-exists.pl
1 2 3 4 => True
6 2 3 3 => True
3 1 4 13 => False
2 1 4 2 => True
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 October 20, 2024. And, please, also spread the word about the Perl Weekly Challenge if you can.
Published by Dimitrios Kechagias on Friday 11 October 2024 00:15
I am in the process of adding OpenWeatherMap support to Xasteria Weather for iOS and the proxy I built is in Perl. Since there was only an old module on CPAN which did not support the current API and was not easily updatable, I released Weather::OWM. It's a very simple module, similar to two other Weather modules I've released in the past (Weather::WeatherKit and Weather::Astro7Timer).
The OpenWeather API has a Free tier with both current weather and forecast, which makes the module useful to anyone interested in fetching weather for any location. E.g.
use Weather::OWM;
my $owm = Weather::OWM->new(key => 'Your API key');
# Get current weather for the Stonehenge area using lat/lon...
my %r = $owm->get_weather(lat => 51.18, lon => -1.83);
# ...and print temperature, humidity, wind speed
say "$r{main}->{temp}C $r{main}->{humidity}% $r{wind}->{speed}m/s"
unless $r{error};
# Get 3h/5d forecast for London, UK...
%r = $owm->get_weather(product => 'forecast', loc => 'London,UK');
# ...print the temperature for every 3 hours over the next 5 days
say scalar(localtime($_->{dt}))." $_->{main}->{temp}C"
for @{$r{list}};
Published by alh on Wednesday 09 October 2024 07:35
Dave writes:
This is my monthly report on work done during September 2024 covered by my TPF perl core maintenance grant.
I spent most of last month continuing to do various bits of code refactoring and test-adding on Extutils::ParseXS, as a precursor to adding reference-counted stack (PERL_RC_STACK) abilities to XS.
SUMMARY:
Total: * 61:23 TOTAL (HH::MM)
Published by Yuki Kimoto on Wednesday 09 October 2024 05:59
How to create a parallel echo server using goroutines in SPVM?
I write a parallel echo server using SPVM::IO::Socket::IP and goroutines, channels, select in SPVM::Go.
See the following test code.
Published by Stuart J Mackintosh on Tuesday 08 October 2024 11:00
We at The Perl and Raku Foundation are supporting the Open Source Pledge initiative.
The Open Source Pledge consists of companies with a shared commitment to paying the maintainers of the open source software they consume, therefore aims to help address sustainability challenges facing the Open Source community.
Open source software is the backbone of much of today’s technology, but it relies heavily on the unpaid work of maintainers. As these volunteers struggle with burnout, turnover among OSS maintainers is high. Without the necessary support, key projects face the risk of disruption, which has far-reaching implications for the broader tech ecosystem. We have already seen the devastating effects of underfunded projects.
The Perl and Raku Foundation goal is to build a strong, healthy and sustainable language ecosystem and community. We also understand the importance of sustained funding for OSS projects. Through our community and core maintenance grants, we will provide support to developers who maintain essential infrastructure. These few dedicated individuals keep key components running, which are relied upon by both commercial systems and the broader internet.
This funding is necessary not only for technical upkeep but also for the non-technical aspects of managing open source communities. Without this support, the risk of losing essential contributors and the valuable work they do is too great.
This model of sustainability funding goes beyond just code contributions and aligns with the goals of the Open Source Pledge. It shows how financial support can be leveraged to maintain not just software, but entire developer ecosystems. This reinforces the importance of initiatives like the Open Source Pledge in supporting the broader open source ecosystem.
The Open Source Pledge sets a new standard for how companies can contribute to OSS sustainability. By joining, companies commit to paying at least $2,000 per year for each developer on staff, with transparency through an annual report that details their payments.
We encourage other organizations to join us in supporting the Open Source Pledge, and using this as a method to set the value of your donations. By doing so, you’ll help ensure that the Perl and Raku ecosystem as well as the wider Open Source efforts remain healthy and sustainable, and that developers are recognized for the critical work they do. For more information about the Open Source Pledge and how to participate, please visit https://osspledge.com/
This is a welcome step in the right direction. "The Open Source Pledge is a crucial step towards ensuring the long-term sustainability of the open source ecosystem and by participating in this pledge, businesses can play a role in fostering innovation and maintaining the digital infrastructure we all rely on." Stuart Mackintosh, President of The Perl and Raku Foundation.
You can support The Perl and Raku Foundation directly using the method described by the Open Source Pledge, or any other amount that you can afford, details on our donations page here.
Published by Unknown on Sunday 06 October 2024 18:55
Published by Unknown on Sunday 06 October 2024 18:53
This is the weekly favourites list of CPAN distributions. Votes count: 59
Week's winner (+3): Parallel::ForkManager
Build date: 2024/10/06 16:52:41 GMT
Clicked for first time:
Increasing its reputation:
These are the five most rated questions at Stack Overflow last week.
Between brackets: [question score / answers count]
Build date: 2024-10-06 16:50:53 GMT
Published on Saturday 05 October 2024 21:02
The examples used here are from the weekly challenge problem statement and demonstrate the working solution.
You are given an array of integers, @ints. Write a script to find the third distinct maximum in the given array. If a third maximum doesn’t exist then return the maximum number.
The majority of the work can be done in a couple of lines. We need only sort the distinct integers in the list and then return either the third largest number or, if none exists, the largest.
sub third_maximum{
my %h;
do{ $h{$_} = undef } for
@_;
my
@sorted = sort {$b <=> $a} keys %h;
return $sorted[2] if
@sorted >= 3;
return $sorted[0];
}
◇
Fragment referenced in 2.
The rest of the code just tests this function.
MAIN:{
say third_maximum 5, 6, 4, 1;
say third_maximum 4, 5;
say third_maximum 1, 2, 2, 3;
}
◇
Fragment referenced in 2.
$ perl perl/ch-1.pl 4 5 1
Your task is to write a program that takes English text as its input and outputs a jumbled version
The rules for jumbling are given as follows:
Looking closer at these rules the main thing we need to concern ourselves with is jumbling the letters with the exception of the first and last. The use of map will ensure the words are processed in order. To make sure the first/last letters are unchanged also depends on detecting punctuation.
Punctuation is determined by a regex. We’ll keep track of the locations so we can add them back later, after jumbling.
Now that we have the punctuation accounted for let’s do the jumble. We’ll do this by generating permutations and randomly select one.
my $p = Algorithm::Permute->new(
[
@{$stripped}[1 ..
@{$stripped} - 2]]
);
my
@p;
if(
@{$stripped} > 2){
my
@r = $p->next();
{
push
@p, [
@r];
@r = $p->next();
redo if
@r;
}
$stripped = [$stripped->[0] ,
@{$p[rand
@p]} ,
$stripped->[
@{$stripped} - 1]];
}
$stripped = join q//,
@{$stripped};
◇
Finally, add the punctuation back in.
The rest of the code drives some tests.
MAIN:{
say q/in the ASCII range match all non-controls./;
say jumble qw/in the ASCII range match all non-controls./;
say q//;
say q/This handy module makes performing permutation.../;
say jumble qw/This handy module makes performing permutation.../;
}
◇
Fragment referenced in 9.
$ perl perl/ch-2.pl in the ASCII range match all non-controls. in the AISCI range macth all non-rloncots. This handy module makes performing permutation... Tihs handy mloude mkaes prifnremog prtaoimetun...
Published by alh on Friday 04 October 2024 11:31
Paul writes:
With the 5.40 release well out of the way, and freed from my PSC commitments, I managed to find a bit more time this month to actually write some useful code.
Hours:
2 = Improvements to op_dump()
for custom operators
1 = Improvements to op_dump()
on existing UNOP_AUX operators
11 = Additions to meta
module: various "list"-type methods,
set_prototype + set_subname on metasubroutines, add_named_sub
helper method, is_class + is_method
Total: 14 hours
Published by Makoto Nozaki on Friday 04 October 2024 08:00
The Japan Perl Association made a generous donation to The Perl and Raku Foundation following their fundraising activity at YAPC::Hiroshima (article link). Here is a thank you message from Olaf Adler:
Japanese translation below:
日本語抄訳
こんにちは。Olaf Alderと申します。The Perl Foundationで後援者様向け広報の担当をしています。今日は日本のPerlコミュニティの皆様に感謝の意を表したく、ご連絡差し上げました。
Japan Perl AssociationとYAPC::Japanの皆様には、長年にわたるご支援を誠に「ありがとう」ございます。特に先日のYAPC::Hiroshimaの大盛況をお祝い申し上げます。写真で見た酒樽募金箱は印象的で、今後、私は日本酒を飲むたびにこのイベントを思い出すでしょう。
YAPCの継続的な成功は素晴らしいです。日本チームの秘訣を世界に伝えてほしいと願っています。私たちも多くを学びたいと思います。
Japan Perl AssociationはThe Perl Foundationの大切なパートナーです。今後とも協力し、Perlの発展に努めましょう。YAPC::Hakodateの盛会をお祈りしています。ありがとうございます!
Published by Mayur Koshti on Wednesday 02 October 2024 16:07
Published by TEJESWAR REDDY on Monday 30 September 2024 10:04
Published by Unknown on Saturday 28 September 2024 22:40
Published by perlancar on Friday 27 September 2024 04:29
dist | author | abstract | date |
---|---|---|---|
Acme-CPANModules-MultipleDispatch | PERLANCAR | List of modules to do smart matching | 2024-08-18T00:05:41 |
Acme-CPANModules-UnixCommandVariants | PERLANCAR | List of various CLIs that are some variants of traditional Unix commands | 2024-08-26T09:48:48 |
Acme-Free-API-ChuckNorris | OODLER | Perl API client for the Chuck Norris Quote API service, https://api.chucknorris.io. | 2024-08-29T18:39:41 |
Acme-Free-API-Stonks | OODLER | Perl API client for the, top 50 stocks discussed on le'Reddit subeddit – r/Wallstreetbets, https://tradestie.com/apps/reddit/api/. | 2024-08-30T16:21:46 |
Acme-Free-API-Ye | OODLER | Perl API client for the Kanye Rest Quote API service, https://kanye.rest/. | 2024-08-28T16:39:49 |
App-BookmarkFeed | SCHROEDER | Create a RSS feed from Markdown files | 2024-08-05T16:33:07 |
App-optex-mask | UTASHIRO | optex data masking module | 2024-08-16T10:14:16 |
App-prefixcat | PERLANCAR | Like Unix `cat` but by default prefix each line with filename | 2024-08-09T12:33:04 |
Ascii-Text | LNATION | module for generating ASCII text in various fonts and styles | 2024-08-29T10:49:18 |
Autoconf-Template | BIGFOOT | autoconfiscation help scripts | 2024-08-06T09:26:35 |
Bio-EnsEMBL | ABECKER | Bio::EnsEMBL – Ensembl Core API | 2024-08-29T16:32:54 |
Business-ID-VehiclePlate | PERLANCAR | Parse Indonesian vehicle plate number | 2024-08-07T00:05:46 |
Catalyst-Plugin-Profile-DBI-Log | BIGPRESH | Capture queries executed during a Catalyst route with DBI::Log | 2024-08-29T23:41:08 |
Circle-Block | CHENGYU | the block module for Circle::Chain SDK | 2024-08-29T06:33:17 |
Circle-Chain | CHENGYU | The great new Circle::Chain! | 2024-08-29T02:33:58 |
Circle-Common | CHENGYU | the common module for Circle::Chain SDK | 2024-08-29T06:31:49 |
Circle-User | CHENGYU | the user module for Circle::Chain SDK | 2024-08-29T06:36:47 |
Circle-Wallet | CHENGYU | the circle chain SDK in PERL | 2024-08-29T06:36:58 |
DBIx-Squirrel | CPANIC | A module for working with databases | 2024-08-08T20:01:38 |
Dancer2-Session-DBI | EPISODEIV | DBI based session engine for Dancer | 2024-08-29T13:55:42 |
DateTime-Locale-FromCLDR | JDEGUEST | DateTime Localised Data from Unicode CLDR | 2024-08-01T22:59:44 |
Dist-Build-XS-Alien | LEONT | Dist::Build extension to use Alien modules. | 2024-08-31T19:19:30 |
File-ShareDir-Tiny | LEONT | Locate per-dist and per-module shared files | 2024-08-25T13:07:29 |
Github-ReleaseFetcher | TEODESIAN | Fetch either the latest or a particular named version of a file in a release from github | 2024-08-13T22:09:19 |
IO-SocketAlarm | NERDVANA | Perform asynchronous actions when a socket changes status | 2024-08-27T06:08:13 |
IPC-MicroSocket | PEVANS | minimal request/response or pub/sub mechanism | 2024-08-05T13:49:53 |
JIRA-REST-Lite | SHINGO | Lightweight wrapper around Jira's REST API | 2024-08-16T01:20:46 |
Langertha | GETTY | The clan of fierce vikings with axe and shield to AId your rAId | 2024-08-03T20:56:05 |
Locale-Unicode-Data | JDEGUEST | Unicode CLDR SQL Data | 2024-08-01T22:43:58 |
Map-Tube-Rome | GDT | Interface to the Rome tube map | 2024-08-27T16:01:05 |
MetaCPAN-Pod-HTML | HAARG | Format Pod as HTML for MetaCPAN | 2024-08-26T14:55:52 |
MooseX-JSONSchema | GETTY | Adding JSON Schema capabilities to your Moose class | 2024-08-03T20:36:33 |
Net-OpenSSH-More | TEODESIAN | Net::OpenSSH submodule with many useful features | 2024-08-09T00:03:26 |
Object-Pad-Operator-Of | PEVANS | access fields of other instances | 2024-08-22T11:30:12 |
OpenFeature-SDK | CATOUC | OpenFeature SDK for Perl | 2024-08-17T19:40:04 |
Plack-App-Catmandu-OAI | NJFRANCK | drop in replacement for Dancer::Plugin::Catmandu::OAI | 2024-08-23T07:58:26 |
Protocol-Sys-Virt-Devel | EHUELS | Development helper for Protocol::Sys::Virt and its dependants | 2024-08-31T20:48:14 |
Protocol-Sys-Virt | EHUELS | Transport independent implementation of the remote LibVirt protocol | 2024-08-31T21:36:13 |
Regex-Common | ARFREITAS | Provide commonly requested regular expressions | 2024-08-12T22:48:17 |
Rope-Cmd | LNATION | Command Line Applications via Rope | 2024-08-30T20:00:03 |
RxPerl-Extras | KARJALA | extra operators for RxPerl | 2024-08-06T10:18:15 |
Sah-SchemaBundle-DNS | PERLANCAR | Schemas related to DNS | 2024-08-04T00:05:19 |
Sah-SchemaBundle-Data-Sah | PERLANCAR | Sah schemas related to Data::Sah | 2024-08-11T00:06:03 |
Sah-SchemaBundle-DataSizeSpeed | PERLANCAR | Sah schemas related to data sizes & speeds (filesize, transfer speed, etc) | 2024-08-02T21:50:19 |
SlapbirdAPM-Agent-Dancer2 | RAWLEYFOW | Agent software for the Perl application performance monitor, Slapbird. slapbirdapm.com | 2024-08-25T20:49:02 |
SlapbirdAPM-Agent-Mojo | RAWLEYFOW | Agent software for the Perl application performance monitor, Slapbird. slapbirdapm.com | 2024-08-09T21:00:04 |
SlapbirdAPM-Agent-Plack | RAWLEYFOW | A Plack agent software for the Perl application performance monitor, Slapbird. slapbirdapm.com | 2024-08-18T02:37:49 |
Syntax-Keyword-Assert | KFLY | assert keyword for Perl | 2024-08-14T13:53:23 |
Task-MemManager | CHRISARG | A memory allocator for low level code in Perl. | 2024-08-25T23:42:18 |
Term-ANSI-Sprintf | LNATION | sprintf with ANSI colors | 2024-08-25T09:46:37 |
Tk-PodViewer | HANJE | Simple ROText based pod viewer. | 2024-08-20T20:06:36 |
kura | KFLY | Store constraints for Data::Checks, Type::Tiny, Moose and more. | 2024-08-18T13:31:06 |
Number of new CPAN distributions this period: 52
Number of authors releasing new CPAN distributions this period: 29
Authors by number of new CPAN distributions this period:
No | Author | Distributions |
---|---|---|
1 | PERLANCAR | 7 |
2 | CHENGYU | 5 |
3 | RAWLEYFOW | 3 |
4 | LNATION | 3 |
5 | OODLER | 3 |
6 | LEONT | 2 |
7 | TEODESIAN | 2 |
8 | JDEGUEST | 2 |
9 | GETTY | 2 |
10 | KFLY | 2 |
11 | PEVANS | 2 |
12 | EHUELS | 2 |
13 | EPISODEIV | 1 |
14 | SCHROEDER | 1 |
15 | NERDVANA | 1 |
16 | BIGFOOT | 1 |
17 | CHRISARG | 1 |
18 | ABECKER | 1 |
19 | SHINGO | 1 |
20 | KARJALA | 1 |
21 | BIGPRESH | 1 |
22 | NJFRANCK | 1 |
23 | ARFREITAS | 1 |
24 | HAARG | 1 |
25 | HANJE | 1 |
26 | GDT | 1 |
27 | UTASHIRO | 1 |
28 | CPANIC | 1 |
29 | CATOUC | 1 |
Published by perlancar on Friday 27 September 2024 04:28
dist | author | abstract | date |
---|---|---|---|
Acme-CPANModules-ModifiedHashes | PERLANCAR | List of modules that provide hashes with modified behaviors | 2024-07-13T02:14:33 |
App-GeometryUtils | PERLANCAR | Utilities related to geometry | 2024-07-07T00:05:12 |
App-LastStats | DAVECROSS | A module to fetch and display Last.fm statistics | 2024-07-28T17:34:18 |
App-PerlGzipScript | SKAJI | Gzip perl scripts to reduce their file size | 2024-07-20T12:49:29 |
App-YtDlpUtils | PERLANCAR | Utilities (mostly wrappers) related to yt-dlp | 2024-07-10T02:59:34 |
Astro-MoonPhase-Simple | BLIAKO | Calculate the phase of the Moon on a given time without too much blah blah | 2024-07-14T14:14:36 |
Audio-Cuefile-Libcue | GREGK | Perl interface to the libcue cuesheet reading library | 2024-07-19T19:43:23 |
Bencher-ScenarioBundle-SmartMatch | PERLANCAR | Scenarios to benchmark switch & smartmatch in Perl | 2024-07-03T09:45:27 |
CVSS | GDT | CVSS (Common Vulnerability Scoring System) command line interface | 2024-07-30T22:11:37 |
Catmandu-Store-OpenSearch | NJFRANCK | A searchable store backed by Opensearch | 2024-07-03T07:23:38 |
Consumer-NonBlock | EXODIST | Send data between processes without blocking. | 2024-07-02T19:53:48 |
Dancer2-Plugin-NYTProf | GEEKRUTH | NYTProf, in your Dancer2 application! | 2024-07-02T13:03:01 |
Data-LnArray-XS | LNATION | Arrays | 2024-07-12T09:58:12 |
Data-Random-Person | SKIM | Generate random person. | 2024-07-05T00:10:57 |
Exercises-API | NOBUNAGA | API Ninja's Exercises API | 2024-07-02T19:49:44 |
Extender | DOMERO | Dynamically enhance Perl objects with additional methods from other modules or custom subroutines | 2024-07-17T10:06:50 |
Kanboard-API | BARBARITO | A Perl interface to the Kanboard API | 2024-07-28T23:46:12 |
KelpX-Controller | BRTASTIC | Base custom controller for Kelp | 2024-07-08T14:43:24 |
MIDI-RtMidi-ScorePlayer | GENE | Play a MIDI score in real-time | 2024-07-10T23:51:51 |
Math-GSL-Alien | HAKONH | Easy installation of the GSL shared library | 2024-07-17T09:42:10 |
Number-Iterator-XS | LNATION | iterate numbers faster | 2024-07-26T03:56:33 |
OpenMP | OODLER | Metapackage for using OpenMP in Perl | 2024-07-19T21:12:29 |
Perl-PrereqScanner-Scanner-DistBuild | LEONT | scan for Dist::Build dependencies | 2024-07-12T12:03:35 |
Plack-App-Catmandu-SRU | NJFRANCK | drop in replacement for Dancer::Plugin::Catmandu::SRU | 2024-07-30T09:27:07 |
SPVM-Resource-Eigen | KIMOTO | Resource for C++ Eigen library | 2024-07-16T23:56:40 |
Sah-SchemaBundle-Country | PERLANCAR | Various Sah schemas related to country codes/names | 2024-07-14T00:05:31 |
Sah-SchemaBundle-Currency | PERLANCAR | Various Sah currency schemas | 2024-07-21T00:06:11 |
Sah-SchemaBundle-DBI | PERLANCAR | Schemas related to DBI | 2024-07-28T00:06:12 |
Shannon-Entropy-XS | LNATION | Calculate the Shannon entropy H of a given input string faster. | 2024-07-18T19:43:55 |
Slack-BlockKit | RJBS | a toolkit for building BlockKit blocks for Slack | 2024-07-04T01:51:26 |
String-Mask-XS | LNATION | mask sensitive data faster | 2024-07-03T21:44:29 |
Syntax-Operator-Is | PEVANS | match operator using Data::Checks constraints | 2024-07-08T14:59:03 |
TableData-Business-ID-Kemenkes-RDA | PERLANCAR | Indonesian RDA (AKG, Angka Kecukupan Gizi) | 2024-07-02T03:05:09 |
Text-Schmutz | RRWO | You̇r screen is quiṭe dirty, please cleȧn it. | 2024-07-11T22:41:24 |
Text-Template-Tiny | JV | Variable substituting template processor | 2024-07-05T11:10:37 |
Tk-Terminal | HANJE | Running system commands in a Tk::Text widget. | 2024-07-03T09:24:21 |
Tradestie-WSBetsAPI | NOBUNAGA | Tradestie's Wallstreet Bets API | 2024-07-01T19:57:16 |
WebService-GrowthBook | DERIV | … | 2024-07-02T11:17:20 |
Whelk | BRTASTIC | A friendly API framework based on Kelp | 2024-07-03T13:59:32 |
Win32-Console-DotNet | BRICKPOOL | Win32 Console .NET interface | 2024-07-29T07:05:25 |
Win32API-RecentFiles | CORION | recently accessed file API functions on Windows | 2024-07-29T18:16:24 |
Number of new CPAN distributions this period: 41
Number of authors releasing new CPAN distributions this period: 28
Authors by number of new CPAN distributions this period:
No | Author | Distributions |
---|---|---|
1 | PERLANCAR | 8 |
2 | LNATION | 4 |
3 | NJFRANCK | 2 |
4 | BRTASTIC | 2 |
5 | NOBUNAGA | 2 |
6 | OODLER | 1 |
7 | GENE | 1 |
8 | RJBS | 1 |
9 | SKAJI | 1 |
10 | DAVECROSS | 1 |
11 | GREGK | 1 |
12 | LEONT | 1 |
13 | GEEKRUTH | 1 |
14 | BARBARITO | 1 |
15 | EXODIST | 1 |
16 | HAKONH | 1 |
17 | GDT | 1 |
18 | DOMERO | 1 |
19 | BRICKPOOL | 1 |
20 | HANJE | 1 |
21 | SKIM | 1 |
22 | RRWO | 1 |
23 | JV | 1 |
24 | CORION | 1 |
25 | DERIV | 1 |
26 | BLIAKO | 1 |
27 | PEVANS | 1 |
28 | KIMOTO | 1 |
Published by Mwenda Kelvin on Thursday 26 September 2024 21:01
Explore how Perl, the language of text manipulation, empowers developers with powerful features for scripting, automation, and robust data…
Published by Mayur Koshti on Thursday 26 September 2024 06:20
Perl can outperform Python, especially in tasks involving text manipulation, regular expressions, and certain I/O-bound operations.
Over the last few months, I’ve been dabbling in using AI to generate or improve code. I have a subscription to GitHub Copilot and I’m finding it a really useful tool for increasing my productivity. Copilot comes in several different flavours, and I’ve been making particular use of a couple of them.
Those two tools alone make me a more efficient programmer. And they’re well worth the $10 a month I pay for my Copilot subscription. But recently I was invited to the preview of Copilot Workspace. And that’s a whole new level. Copilot Workspace takes a GitHub issue as its input and returns a complete, multifile pull request that implements the required change. I’ve been playing with it for small tweaks, but I decided the time was right to do something more substantial. I planned to write an entire Dancer app by defining issues and asking Copilot to implement the code. Here’s what happened. You can follow along at the GitHub repo.
I decided I would start from the standard, automatically generated Dancer2 app. So I ran dancer2 gen -a Example and committed the output from that. It was then time for the first issue. I decided to start by adding (empty) routes for user registration and login. I opened the issue in the Copilot Workspace and asked the AI for some suggested code. It didn’t really understand the idea of empty routes – but the pull request seemed pretty good. I merged the PR and moved on to the next issue – to add basic registration and login screens. Again, the pull request did a little more than I asked for – adding a bit more registration and login logic – but the code was good.
As an aside, you’ll notice that the PRs are all correctly linked to the correct issues and contain substantial information about the changes. This is all generated by the AI.
For the next step, we needed a database table to store the users. I asked Copilot to use SQLite and it gave me what I wanted – once again, going above and beyond. For the first time, its overenthusiasm was slightly annoying, because it added some database code to store new users and I hadn’t told it that we would be using DBIx::Class. So that was the next issue and the next pull request. Note that the pull request even includes adding DBIx::Class to the requisites in Makefile.PL.
Time for some unit tests (ok, maybe the best time was a few PRs ago!). The issue description was simple – “Write unit tests for everything we have so far“. Maybe it was too simple – as this was the first time the AI seemed to struggle a bit. I was merging the PRs without really checking them and the PR introduced a lot of useful tests – but many of them failed. Part of the problem here is that (as far as I can see) Copilot Workspace has no way to run the code it produces – so it was guessing how well it was doing. It took a few iterations to get that right – it basically boiled down to the database schema not being loaded into the database before the tests were run. At times while we were working through these problems, I was reminded of someone (I think it was Simon Willison) describing an AI programming assistant as “an overconfident, overenthusiastic intern”. Luckily, unlike an intern, Copilot never gets annoyed with you telling it to try again and providing more and more information to help it get to the bottom of a problem.
After a while, we had a working test suite and were back on track.
So we were back at adding features to the application. I decided the next thing we needed was to display the logged-in user’s username and email address on the main page. That seemed simple enough and worked first time. About this time I was getting annoyed with the standard Dancer2 web page, so we removed most of that. Then I switched from Dancer’s default “simple” templating system to the Template Toolkit [issue / PR].
While we were tidying up the look and feel, we added login and logout buttons [issue / PR] and a register button on the logged out page [issue / PR]. This led to some more confusion for a while as logging out didn’t work. It turned out the AI had used outdated code to destroy the session and I had to get very specific before it would do the right thing [issue / PR].
We then added some more tests [issue / PR], displayed registration and login errors [issue / PR] and ensured we were storing the passwords in encrypted form (to be honest, I’m slightly disappointed that the AI didn’t do that by default) [issue / PR].
At this point (and I don’t know why I didn’t do it sooner), we replaced the UI with something using Bootstrap [issue / PR]. That led to a bit more tweaking of the buttons [issue / PR].
At this point, I had basically got to where I wanted to be. I had an app that didn’t do anything useful, but let you register, login and log out. And I’d done it all pretty quickly and without writing very much code.
Then I decided to push it too far.
The thing that I actually wanted to achieve at this point was to add social registration and login to the site. I created an issue – Allow users to register and login using a Google account – and Copilot gave me some code. But at this point, it’s not just about code. You also need to configure stuff at Google in order to get this working. And, while Copilot gave me some information about what I needed to do, I haven’t yet been able to get it working. This is a good example of the limitations of AI-powered programming. It’s great at generating code, but (so far, at least) not so good at keeping up to date with how to interface with external systems. Oh, and there’s the problem we saw earlier about it not actually running the tests.
So, how do I think the experiment went? I was impressed. There was a lot of code generated that was as good or better than I would have written myself. There are certainly the problems that I mentioned above, but this stuff is improving at such an incredible rate that I really can’t see those problems still existing in a year.
I’ve started using Copilot Workspace for a lot more of my projects. And I’m happy with the results I’ve got.
What about you? Have you used any version of Copilot to help with your coding? How successful has it been?
The post Dancing with Copilot Workspace appeared first on Perl Hacks.
VelociPerl is a closed source fork of Perl that claims performance gains of 45% over the stock (“your dad’s Perl” in their parlance) based on some public benchmarks. I will not go into how they achieved this performance boost, or why they released it as closed source, or even “but why the heck did you release it as closed source?”, as you can follow the Reddit discussion. However, even a modest speed gain may be useful in some applications, so I decided to dive in a a little bit deeper.
Some of the benchmarks are numerical e.g. a linear system solver, generating random numbers but others are more relevant to garden variety Perl tasks, e.g. generating objects as blessed hashes. These tasks may appear in the context of some applications, so it is nice to know there are some benefits, but why not come up with a composite task and benchmark it? My usage of Perl involves random number generation, operations on tasks, creation of objects, string concatenation and function calling, so I figured there should be a way to combine all of them together and take VelociPerl for a ride.
Consider the following code that executes two benchmarks:
use v5.38;
use Benchmark qw(timethis); # for benchmarking
my $Length_of_accesstest = 1_000_000;
my $Length_of_gentest=100_000;
my $class = 'HashingAround';
sub generate_random_string(@alphabet) {
my $len = scalar @alphabet;
my $length = int( rand(100) ) + 1; # random length between 1 and 100
return join '', @alphabet[ map { rand $len } 1 .. $length ];
}
my %hash_of_seqs;
for ( 1 .. $Length_of_accesstest ) {
my $key = generate_random_string(('A' .. 'Z'));
my $val = bless \do { my $anon_scalar = $key }, $class;
$hash_of_seqs{$key} = $val;
}
say "=" x 80;
say "\tTiming hash access using timethis";
timethis(
20,
sub {
while ( my ( $seq_id, $seq ) = each %hash_of_seqs ) {
## worthless access to seq to force the sequence to be copied in memory
my $sequence = $seq;
}
}
);
say "=" x 80;
say "\tTiming hash generation using timethis";
timethis(
10,
sub {
my %hash_of_seqs;
for ( 1 .. $Length_of_gentest ) {
my $key = generate_random_string(('A' .. 'Z'));
my $val = bless \do { my $anon_scalar = $key }, $class;
$hash_of_seqs{$key} = $val;
}
}
);
To switch the Perl interpreter one simply changes the shebang line. In my oldish dual Xeon E5-2697 v4, I obtained the following results
* **VelociPerl** :
```text
(base) chrisarg@chrisarg-HP-Z840-Workstation:~/software-dev/velociperlHash$ ./testHash_speed_vperl.pl
================================================================================
Timing hash access using timethis
timethis 20: 11 wallclock secs (11.04 usr + 0.00 sys = 11.04 CPU) @ 1.81/s (n=20)
================================================================================
Timing hash generation using timethis
timethis 10: 10 wallclock secs ( 9.80 usr + 0.01 sys = 9.81 CPU) @ 1.02/s (n=10)
Walking the hash was not materially different between the two interpreters, but the more compute intense task that involved random numbers, string operation and blessing of objects was ~30% faster. This gain may or may not justify using a closed source version of Perl to you. But it is worth noting that one may be able to tweak the compilation of the Perl source (which appears to be a major source of the claimed gains) to generate faster executing Perl code. Perhaps an approach that one can try with an open sourced fork?